net.sf.click.extras.control
Class DateField

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Field
          extended bynet.sf.click.control.TextField
              extended bynet.sf.click.extras.control.DateField
All Implemented Interfaces:
Control, Serializable

public class DateField
extends TextField

Provides a Date Field control:   <input type='text'><img>.

Date Field
The DateField control provides a Date entry field and a popup DHTML Calendar <div>. Users can either key in a Date value or select a Date using the Calendar.

The Calendar popup is provided by the JSCalendar library by Dynarch.com. The Calendar popup is created as a <div> element using JavaScript. To enable the Calenar popup, reference $cssImports and $jsImports in the page template. For example:

 <html>
 <head>
 $cssImports
 </head>
 <body>
 $form
 </body>
 </html>
 $jsImports 
The default Calendar style is 'system' which has a similar appearance to the Windows Calendar control. The JSCalendar styles include: The DateField JavaScript, CSS and image resources are automatically deployed to the click/calendar web directory on application startup.

See also W3C HTML reference INPUT

Author:
Malcolm Edgar
See Also:
Serialized Form

Field Summary
protected  String calendarPattern
          The JavaScript DHTML Calendar pattern.
protected  Date date
          The DateField's date value.
protected  SimpleDateFormat dateFormat
          The date format.
protected  String formatPattern
          The date format pattern value.
static String HTML_IMPORTS
          The HTML import statements.
protected  boolean showTime
          The Calendar popup show time display bar flag.
protected  String style
          The JSCalendar CSS style, default value: system.
 
Fields inherited from class net.sf.click.control.TextField
maxLength, minLength, size, VALIDATE_TEXTFIELD_FUNCTION
 
Fields inherited from class net.sf.click.control.Field
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.click.Control
CONTROL_MESSAGES
 
Constructor Summary
DateField()
          Create a Date Field with no name defined.
DateField(String name)
          Construct the Date Field with the given name.
DateField(String name, boolean required)
          Construct the Date Field with the given name and required status.
DateField(String name, String label)
          Construct the Date Field with the given name and label.
DateField(String name, String label, boolean required)
          Construct the Date Field with the given name, label and required status.
DateField(String name, String label, int size)
          Construct the Date Field with the given name, label and size.
DateField(String name, String label, int size, boolean required)
          Construct the Date Field with the given name, label, size and required status.
 
Method Summary
 String getCalendarPattern()
          Return the JavaScript DHTML Calendar pattern.
 Date getDate()
          Return the field Date value, or null if value was empty or a parsing error occurred.
 SimpleDateFormat getDateFormat()
          Return the SimpleDateFormat for the formatPattern property.
protected  int getFirstDayOfWeek()
          Return the first day of the week.
 String getFormatPattern()
          Return the SimpleDateFormat pattern.
 String getHtmlImports()
          Return the DateField calendar.js and calendar-{lang}.js includes.
protected  Locale getLocale()
          Returns the Locale that should be used in this control.
 boolean getShowTime()
          Return true if the DHTML Calendar popup will show the time display bar.
 String getStyle()
          Return the JSCalendar CSS style.
 Timestamp getTimestamp()
          Return the Timestamp value, or null if value was empty or a parsing error occured.
 Object getValueObject()
          Return the field Date value, or null if value was empty or a parsing error occured.
 void onDeploy(ServletContext servletContext)
          Deploy the Calendar Javascript and CSS resources to the web app directory click/calendar.
protected  String parseDateFormatPattern(String pattern)
          Return the JavaScript Calendar pattern for the given Java DateFormat pattern.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the DateField.
 void setDate(Date date)
          Set the field Date value.
 void setFormatPattern(String pattern)
          Set the SimpleDateFormat pattern.
 void setName(String name)
           
 void setShowTime(boolean showTime)
          Set the DHTML Calendar popup show the time display bar flag.
 void setStyle(String style)
          Set the JSCalendar CSS style.
 void setValue(String value)
          Set the DateField value.
 void setValueObject(Object object)
          Set the date value of the field using the given object.
 void validate()
          Validate the DateField request submission.
 
Methods inherited from class net.sf.click.control.TextField
getControlSizeEst, getMaxLength, getMinLength, getSize, getTag, getType, getValidationJavaScript, setMaxLength, setMinLength, setSize
 
Methods inherited from class net.sf.click.control.Field
bindRequestValue, getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setWidth
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDestroy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTML_IMPORTS

public static final String HTML_IMPORTS
The HTML import statements.

See Also:
Constant Field Values

date

protected Date date
The DateField's date value.


calendarPattern

protected String calendarPattern
The JavaScript DHTML Calendar pattern.


dateFormat

protected SimpleDateFormat dateFormat
The date format.


formatPattern

protected String formatPattern
The date format pattern value.


showTime

protected boolean showTime
The Calendar popup show time display bar flag.


style

protected String style
The JSCalendar CSS style, default value: system.   Available styles include: [blue, blue2, brown, green, system, tas, win2k-1, win2k-2, win2k-cold-1, win2k-cold-2]

Constructor Detail

DateField

public DateField(String name)
Construct the Date Field with the given name.

The date format pattern will be set to dd MMM yyyy.

Parameters:
name - the name of the field

DateField

public DateField(String name,
                 String label)
Construct the Date Field with the given name and label.

The date format pattern will be set to dd MMM yyyy.

Parameters:
name - the name of the field
label - the label of the field

DateField

public DateField(String name,
                 boolean required)
Construct the Date Field with the given name and required status.

The date format pattern will be set to dd MMM yyyy.

Parameters:
name - the name of the field
required - the field required status

DateField

public DateField(String name,
                 String label,
                 boolean required)
Construct the Date Field with the given name, label and required status.

The date format pattern will be set to dd MMM yyyy.

Parameters:
name - the name of the field
label - the label of the field
required - the field required status

DateField

public DateField(String name,
                 String label,
                 int size)
Construct the Date Field with the given name, label and size.

Parameters:
name - the name of the field
label - the label of the field
size - the size of the field

DateField

public DateField(String name,
                 String label,
                 int size,
                 boolean required)
Construct the Date Field with the given name, label, size and required status.

Parameters:
name - the name of the field
label - the label of the field
size - the size of the field
required - the field required status

DateField

public DateField()
Create a Date Field with no name defined.

Please note the control's name must be defined before it is valid.

Method Detail

getCalendarPattern

public String getCalendarPattern()
Return the JavaScript DHTML Calendar pattern. The DHTML Calendar pattern is defined when you set the format pattern.

Returns:
the JavaScript DHTML Calendar pattern

getDate

public Date getDate()
Return the field Date value, or null if value was empty or a parsing error occurred.

Returns:
the field Date value

setDate

public void setDate(Date date)
Set the field Date value.

Parameters:
date - the Date value to set

getDateFormat

public SimpleDateFormat getDateFormat()
Return the SimpleDateFormat for the formatPattern property.

Returns:
the SimpleDateFormat for the formatPattern

getFormatPattern

public String getFormatPattern()
Return the SimpleDateFormat pattern.

Returns:
the SimpleDateFormat pattern

setFormatPattern

public void setFormatPattern(String pattern)
Set the SimpleDateFormat pattern.

SimpleDateFormat Pattern Characters

Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

Parameters:
pattern - the SimpleDateFormat pattern

getHtmlImports

public String getHtmlImports()
Return the DateField calendar.js and calendar-{lang}.js includes.

Returns:
the HTML head import statements for the control stylesheet and JavaScript files

setName

public void setName(String name)
Parameters:
name - of the control
Throws:
IllegalArgumentException - if the name is null
See Also:
AbstractControl.setName(String)

getTimestamp

public Timestamp getTimestamp()
Return the Timestamp value, or null if value was empty or a parsing error occured.

Returns:
the Timestamp value

getShowTime

public boolean getShowTime()
Return true if the DHTML Calendar popup will show the time display bar.

Returns:
true if the DHTML Calendar popup will show the time display bar

setShowTime

public void setShowTime(boolean showTime)
Set the DHTML Calendar popup show the time display bar flag.

Parameters:
showTime - the flag to show the Calendar time display bar

getStyle

public String getStyle()
Return the JSCalendar CSS style.

Available styles include: [blue, blue2, brown, green, system, tas, win2k-1, win2k-2, win2k-cold-1, win2k-cold-2]

Returns:
the JSCalendar CSS style

setStyle

public void setStyle(String style)
Set the JSCalendar CSS style.

Parameters:
style - the JSCalendar CSS style

setValue

public void setValue(String value)
Set the DateField value.

Parameters:
value - the DateField value

getValueObject

public Object getValueObject()
Return the field Date value, or null if value was empty or a parsing error occured.

Returns:
the Date object representation of the Field value

setValueObject

public void setValueObject(Object object)
Set the date value of the field using the given object.

Parameters:
object - the object value to set

onDeploy

public void onDeploy(ServletContext servletContext)
Deploy the Calendar Javascript and CSS resources to the web app directory click/calendar.

Parameters:
servletContext - the servlet context

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the DateField.

Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()

validate

public void validate()
Validate the DateField request submission.

A field error message is displayed if a validation error occurs. These messages are defined in the resource bundle:

  • /click-control.properties
    • field-maxlength-error
    • field-minlength-error
    • field-required-error
  • /net/sf/click/extras/control/DateField.properties
    • date-format-error


getFirstDayOfWeek

protected int getFirstDayOfWeek()
Return the first day of the week. For example e.g., Sunday in US, Monday in France and Australia.

Returns:
the first day of the week

getLocale

protected Locale getLocale()
Returns the Locale that should be used in this control.

Returns:
the locale that should be used in this control

parseDateFormatPattern

protected String parseDateFormatPattern(String pattern)
Return the JavaScript Calendar pattern for the given Java DateFormat pattern.

Parameters:
pattern - the Java DateFormat pattern
Returns:
JavaScript Calendar pattern