Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
$URL: https://source.sakaiproject.org/svn/jsf/tags/sakai-10.0/jsf-widgets/src/java/org/sakaiproject/jsf/renderer/OutputDateRenderer.java $ $Id: OutputDateRenderer.java 105077 2012-02-24 22:54:29Z ottenhoff@longsight.com $ Copyright (c) 2003, 2004, 2005, 2006, 2008 The Sakai Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 
 package org.sakaiproject.jsf.renderer;
 
 import java.util.Date;
 
 

OutputDateRenderer is an HTML renderer for Sakai 2.0 JSF outputDate.

Author(s):
esmiley@stanford.edu
based partly on some previous code in DateOutput.java ggolden@umich.edu
Version:
$Revision: 105077 $
 
 public class OutputDateRenderer extends Renderer
 {
  

Todo:
add more configuration
 
   private static final String OUTPUT_DATE;// for now we'll jsut use this one...
   private static final String OUTPUT_DATE_TIME;
   private static final String OUTPUT_DATE_SECS;
   private static final String OUTPUT_TIME;
   private static final String OUTPUT_SECS;
 
 // we have static resources for our date formats
   static
   {
      = cr.get("outputDate");
      = cr.get("outputDateTime");
      = cr.get("outputDateTimeSecs");
      = cr.get("outputTime");
      = cr.get("outputTimeSecs");
   }
 
   public boolean supportsComponentType(UIComponent component)
   {
     return (component instanceof UIOutput);
   }



 

Faces render output method .

Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker

Parameters:
context FacesContext for the current request
component UIComponent being rendered
Throws:
java.io.IOException if an input/output error occurs
 
 
   public void encodeBegin(FacesContext contextUIComponent componentthrows
     IOException
   {
     if (!component.isRendered())
     {
       return;
     }
 
     ResponseWriter writer = context.getResponseWriter();
 
     // this is a date object representing our date
     // this is a debug line, we are losing our date
     Date date = ((Date) RendererUtil.getDefaultedAttribute(
      contextcomponent"value"new Date()));
    // this is the formatted output representation of the date
    String dateStr = "";
    String formatStr = getFormatString(contextcomponent);
    dateStr = format(dateformatStr);
    String clientId = null;
    if (component.getId() != null &&
      !component.getId().startsWith(.))
    {
      clientId = component.getClientId(context);
    }
    if (clientId != null)
    {
      writer.startElement("span"component);
      writer.writeAttribute("id"clientId"id");
    }
    writer.write(dateStr);
    if (clientId != null)
    {
      writer.endElement("span");
    }
  }

  
Obtain the format string from the

Parameters:
context Faces context
component the component
Returns:
a date format String
  private String getFormatString(FacesContext contextUIComponent component)
  {
    String fmt = ;
    String showTime = (String) RendererUtil.getAttribute(contextcomponent"showTime");
    String showDate = (String) RendererUtil.getAttribute(contextcomponent"showDate");
    String showSeconds = (String) RendererUtil.getAttribute(contextcomponent"showSeconds");
//    boolean hasTime = true; //"true".equals(showTime)? true: false;
//    boolean hasDate = true; //"true".equals(showDate)? true: false;
//    boolean hasSeconds = true; //"true".equals(showSeconds) && hasTime ? true: false;
    boolean hasTime = "true".equals(showTime)? truefalse;
    boolean hasDate = "true".equals(showDate)? truefalse;
    boolean hasSeconds = "true".equals(showSeconds) && hasTime ? truefalse;
    if (hasTime)
    {
      if (hasDate)
      {
        if (hasSeconds)
        {
          fmt = ;
        }
        else
        {
          fmt = ;
        }
      }
      else
      {
        if (hasSeconds)
        {
          fmt = ;
        }
        else
        {
          fmt = ;
        }
      }
    }
    return fmt;
  }

  

Parameters:
date
Returns:
the formatted date String
  private String format(Date dateString format)
  {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(date);
  }
New to GrepCode? Check out our FAQ X