org.apache.myfaces.custom.calendar
Class HtmlCalendarRenderer

java.lang.Object
  extended by javax.faces.render.Renderer
      extended by org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer
          extended by org.apache.myfaces.custom.calendar.HtmlCalendarRenderer

public class HtmlCalendarRenderer
extends org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer

Render a "calendar" which the user can use to choose a specific day.

This renderer behaves quite differently for "inline" and "popup" calendars.

When inline, this component automatically creates child components (text and link components) to represent all the dates, scrollers, etc. within itself and renders those children. Clicking on any link in the component causes the surrounding form to immediately submit.

When popup, this component just renders an empty span with the component id, and a dozen or so lines of javascript which create an instance of a "tomahawk calendar object", set its properties from the properties on the associated HtmlInputCalendar component, and then invoke it. That javascript object then dynamically builds DOM objects and attaches them to the empty span. This component also renders a button or image that toggles the visibility of that empty span, thereby making the popup appear and disappear.

Note that the two ways of generating the calendar use totally different code; one implementation is here and the other is in a javascript resource file. For obvious reasons the appearance of the two calendars should be similar, so if a feature is added in one place it is recommended that the other be updated also.

The behaviour of both of the Calendar objects varies depending upon the "current locale". This is derived from getViewRoot().getLocale(), which is normally set according to the browser preferences; users whose browsers have "english" as the preferred language will get the "en" locale, while users with "deutsch" as the preferred language will get the "de" locale. One specific example is the "first day of week" (ie the day displayed at the left of each week row); this is "sunday" for the english locale, and "monday" for the german locale. There is currently no way for the calendar component to be configured to force a specific firstDayOfWeek to be used for all users.

Version:
$Revision: 1301249 $ $Date: 2012-03-15 17:24:05 -0500 (Thu, 15 Mar 2012) $
Author:
Martin Marinschek (latest modification by $Author: lu4242 $)

Nested Class Summary
static class HtmlCalendarRenderer.CalendarDateTimeConverter
           
static interface HtmlCalendarRenderer.DateConverter
           
 
Constructor Summary
HtmlCalendarRenderer()
           
 
Method Summary
static void addScriptAndCSSResources(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
          Used by the x:inputDate renderer : HTMLDateRenderer
 void decode(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
           
 void encodeEnd(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
           
 Object getConvertedValue(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, Object submittedValue)
           
static String getLocalizedLanguageScript(javax.faces.context.FacesContext facesContext, DateFormatSymbols symbols, int firstDayOfWeek, javax.faces.component.UIComponent uiComponent, String popupCalendarVariable)
          Creates and returns a String which contains the initialisation data for the popup calendar control as a sequence of javascript commands that assign values to properties of a javascript object whose name is in parameter popupCalendarVariable.
static void getScriptBtn(javax.faces.context.ResponseWriter writer, javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, String dateFormat, String popupButtonString, FunctionCallProvider prov)
           
protected static boolean isDisabled(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent)
           
static String[] mapMonths(DateFormatSymbols symbols)
           
static String[] mapShortMonths(DateFormatSymbols symbols)
           
 
Methods inherited from class org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer
getActionUrl, getChildCount, getChildren, getClientId, renderId, shouldRenderId, toUri
 
Methods inherited from class javax.faces.render.Renderer
convertClientId, encodeBegin, encodeChildren, getRendersChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlCalendarRenderer

public HtmlCalendarRenderer()
Method Detail

encodeEnd

public void encodeEnd(javax.faces.context.FacesContext facesContext,
                      javax.faces.component.UIComponent component)
               throws IOException
Overrides:
encodeEnd in class javax.faces.render.Renderer
Throws:
IOException

addScriptAndCSSResources

public static void addScriptAndCSSResources(javax.faces.context.FacesContext facesContext,
                                            javax.faces.component.UIComponent component)
Used by the x:inputDate renderer : HTMLDateRenderer


getLocalizedLanguageScript

public static String getLocalizedLanguageScript(javax.faces.context.FacesContext facesContext,
                                                DateFormatSymbols symbols,
                                                int firstDayOfWeek,
                                                javax.faces.component.UIComponent uiComponent,
                                                String popupCalendarVariable)
Creates and returns a String which contains the initialisation data for the popup calendar control as a sequence of javascript commands that assign values to properties of a javascript object whose name is in parameter popupCalendarVariable.

Parameters:
firstDayOfWeek - is in java.util.Calendar form, ie Sun=1, Mon=2, Sat=7

getScriptBtn

public static void getScriptBtn(javax.faces.context.ResponseWriter writer,
                                javax.faces.context.FacesContext facesContext,
                                javax.faces.component.UIComponent uiComponent,
                                String dateFormat,
                                String popupButtonString,
                                FunctionCallProvider prov)
                         throws IOException
Throws:
IOException

mapMonths

public static String[] mapMonths(DateFormatSymbols symbols)

mapShortMonths

public static String[] mapShortMonths(DateFormatSymbols symbols)

decode

public void decode(javax.faces.context.FacesContext facesContext,
                   javax.faces.component.UIComponent component)
Overrides:
decode in class javax.faces.render.Renderer

isDisabled

protected static boolean isDisabled(javax.faces.context.FacesContext facesContext,
                                    javax.faces.component.UIComponent uiComponent)

getConvertedValue

public Object getConvertedValue(javax.faces.context.FacesContext facesContext,
                                javax.faces.component.UIComponent uiComponent,
                                Object submittedValue)
                         throws javax.faces.convert.ConverterException
Overrides:
getConvertedValue in class javax.faces.render.Renderer
Throws:
javax.faces.convert.ConverterException


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.