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/InputDateRenderer.java $ $Id: InputDateRenderer.java 111189 2012-08-09 22:29:30Z ottenhoff@longsight.com $ Copyright (c) 2005, 2006, 2007, 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;
 import java.util.Map;
 

Description:

Render the custom color picker control.

Copyright: Copyright (c) 2004

Organization: Sakai Project

Author(s):
Ed Smiley
Version:
$id: $
Todo:
handle showSeconds
 
 
 public class InputDateRenderer
   extends Renderer
 {
   // calendar popup configuration
   private static final String HEIGHT = "16";
   private static final String WIDTH = "16";
   private static final boolean inputTimeSeconds = true//todo
 
  
Bean to get resources for specific locale.
 
   private class ConfigurationResourceBean
   {
     // calendar popup configuration
     private final String cursorStyle;
     private final String clickAlt;
     private final String calendarPath;
     private final String calendarIcon;
     // input date and time configuration, from global resources
     private final boolean inputMonthFirst;
     private final String dateFormatString;
     private final SimpleDateFormat dateFormat;
     private final SimpleDateFormat timeFormat;
     private final SimpleDateFormat dateTimeFormat;
     private final String dateHint;
     private final String timeHint;
 
     public ConfigurationResourceBean(final Locale locale)
     {
       ConfigurationResource cr = new ConfigurationResource(locale);
       String resources = cr.get("resources");
        = cr.get("picker_style");
        = "/" + resources + "/" + cr.get("inputDatePopup");
        = "/" + resources + "/" + cr.get("inputDateImage");
        = cr.get("date_pick_alt");
        = Boolean.valueOf(cr.get("inputMonthFirst"));
       boolean inputTimeColon = Boolean.valueOf(cr.get("inputTimeColon"));
       boolean inputTime24 = Boolean.valueOf(cr.get("inputTime24"));
        = cr.get("inputDateHint");
        = cr.get("inputTimeHint");
 
       String timeFormatString;
       if ()
       {
          = cr.get("inputMonthFirstFormat");
       }
       else
       {
          = cr.get("inputDayFirstFormat");
      }
      if (inputTimeColon)
      {
        if (inputTime24)
        {
          timeFormatString = cr.get("inputTimeColonFormat24");
        }
        else
        {
          timeFormatString = cr.get("inputTimeColonFormatAMPM");
        }
      }
      else
      {
        if (inputTime24)
        {
          timeFormatString = cr.get("inputTimeDotFormat24");
        }
        else
        {
          timeFormatString = cr.get("inputTimeDotFormatAMPM");
        }
      }
       = new SimpleDateFormat(locale);
       = new SimpleDateFormat(timeFormatStringlocale);
       =
        new SimpleDateFormat( + " " + timeFormatStringlocale);
    }
    public String getCursorStyle()
    {
      return ;
    }
    public String getClickAlt()
    {
      return ;
    }
    public String getCalendarPath()
    {
      return ;
    }
    public String getCalendarIcon()
    {
      return ;
    }
    public boolean isInputMonthFirst()
    {
      return ;
    }
    public String getDateFormatString()
    {
      return ;
    }
    {
      return ;
    }
    {
      return ;
    }
    {
      return ;
    }
    public String getDateHint()
    {
      return ;
    }
    public String getTimeHint()
    {
      return ;
    }
  }
  public boolean supportsComponentType(UIComponent component)
  {
    return (component instanceof UIInput);
  }


  
decode the value

Parameters:
context
component
  public void decode(FacesContext contextUIComponent component)
  {
    if (RendererUtil.isDisabledOrReadonly(contextcomponent))
    {
      return;
    }
    // get request parameters
    Map requestParameterMap = context.getExternalContext()
    String clientId = component.getClientId(context);
    String dateStr = (StringrequestParameterMap.get(clientId + "_date");
    String timeStr = (StringrequestParameterMap.get(clientId + "_time");
    if(dateStr==null && timeStr==nullreturn;
    EditableValueHolder ev = (EditableValueHoldercomponent;
    // create holder for subcomponent values
//    Map dateParts = new HashMap();
//    // get the subcomponent values
//    // the hidden clientId maintains all the values togethr
//
//    dateParts.put("clientId", clientId);
//    dateParts.put("date", date);
//    dateParts.put("time", time);
//    // set the submitted value to the subcomponent value map
//    ev.setSubmittedValue(dateParts);
    ConfigurationResourceBean crb = new ConfigurationResourceBean(LocaleUtil.getLocale(context));
    Date date = null;
    if(dateStr==null && timeStr!=null)
    {
      try
      {
        date = crb.getTimeFormat().parse(timeStr);
      }
      catch (ParseException ex)
      {
        //leave null
      }
    }
    else if(dateStr!=null && timeStr==null)
    {
      try
      {
        date = crb.getDateFormat().parse(dateStr);
      }
      catch (ParseException ex)
      {
        //leave null
      }
    }
    else
    {
      try
      {
        date = crb.getDateTimeFormat().parse(dateStr + " " + timeStr);
      }
      catch (ParseException ex)
      {
        //leave null
      }
    }
    ev.setSubmittedValue(date);
  }


  

Faces render output method .

Parameters:
context FacesContext for the current request
component UIComponent being rendered
Throws:
java.io.IOException if an input/output error occurs
  public void encodeEnd(FacesContext context,
                        UIComponent componentthrows IOException
  {
    if (RendererUtil.isDisabledOrReadonly(contextcomponent) || !component.isRendered())
    {
      return;
    }
    ResponseWriter writer = context.getResponseWriter();
    String clientId = component.getClientId(context);
    /////////////////////////////////////////////////////////
    //  VALUE HOLDER AND ATTRIBUTES
    /////////////////////////////////////////////////////////
    ConfigurationResourceBean crb = new ConfigurationResourceBean(LocaleUtil.getLocale(context));
    String dateString = "";
    String timeString = "";
    Date date = null;
    Date submittedValue =
      (Date) ( (EditableValueHoldercomponent).getSubmittedValue();
    if (submittedValue != null)
    {
      date = submittedValue;
    }
    else
    {
      Object value = ( (ValueHoldercomponent).getValue();
      if (value instanceof Date)
      {
        date = (Datevalue;
      }
      else if (value instanceof String)
      {
        try
        {
          date = crb.getDateTimeFormat().parse((Stringvalue);
        }
        catch (ParseException ex)
        {
          // leave alone
        }
      }
    }
    if (date !=null)
    {
      dateString = crb.getDateFormat().format(date);
      timeString = crb.getTimeFormat().format(date);
    }
    // display options attributes
    boolean showDate;
    boolean showTime;
    boolean showSecond;
    showDate = "true".equals
      ((String) RendererUtil.getAttribute(contextcomponent"showDate"));
    showTime = "true".equals
      ((String) RendererUtil.getAttribute(contextcomponent"showTime"));
    showSecond = "true".equals
      ((String) RendererUtil.getAttribute(contextcomponent"showSecond"));
    /////////////////////////////////////////////////////////
    //  RENDER DATE INPUT
    /////////////////////////////////////////////////////////
    if (showDate)
    {
      writer.write("<i>&#160;" + crb.getDateHint() + "&#160;</i>" );
      String dateId = clientId + "_date" ;
      String type ="text";
      writer.write("<input type=\"" + type + "\"" +
                   " size=\"" + crb.getDateFormatString().length() + "\"" +
                   " name=\"" + dateId + "\"" +
                   " id=\"" + dateId + "\"" +
                   " value=\"" + dateString + "\">&#160;");
      // script creates unique javascript popup calendar object
      String calRand = "cal" + ("" + Math.random()).substring(2);
      String calendar;
      if (crb.isInputMonthFirst())
      {
        calendar = "calendar2";
      }
      else
      {
        calendar = "calendar1";
      }
      String calScript =
        "var " + calRand + " = new " + calendar"(" +
        "document.getElementById('" + dateId + "'));" +
        "" + calRand + ".year_scroll = true;" +
        "" + calRand + ".time_comp = false;";
      // calendar icon with onclick to script
      writer.write("&#160;<img");
      writer.write("  id=\"" + clientId + "_datePickerPopup" + "\"");
      writer.write("  width=\"" +  + "\"\n");
      writer.write("  height=\"" +  + "\"\n");
      writer.write("  style=\"" + crb.getCursorStyle() + "\" ");
      writer.write("  src=\"" + crb.getCalendarIcon() + "\"\n");
      writer.write("  border=\"0\"\n");
      writer.write("  onclick=");
      writer.write("\"javascript:" + calScript +
                   calRand + ".popup('','" + crb.getCalendarPath() + "');\"\n");
      writer.write("  alt=\"" + crb.getClickAlt() + "\"\n");
      writer.write(" />&#160;&#160;\n");
    }
    /////////////////////////////////////////////////////////
    //  RENDER TIME INPUT
    /////////////////////////////////////////////////////////
    if (showTime)
    {
      writer.write("<i>&#160;" + crb.getTimeHint() + "&#160;</i>" );
      String timeId = clientId + "_time" ;
      writer.write("<input type=\"text\"" +
                   " size=\"" + (crb.getDateFormatString().length() + 1) + "\"" +
                  " name=\"" + timeId + "\"" +
                  " id=\"" + timeId + "\"" +
                  " value=\"" + timeString + "\">&#160;");
    }
  }
New to GrepCode? Check out our FAQ X