org.apache.wicket.extensions.yui.calendar
Class DateTimeField

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
                  extended by org.apache.wicket.markup.html.form.FormComponent<T>
                      extended by org.apache.wicket.markup.html.form.FormComponentPanel<java.util.Date>
                          extended by org.apache.wicket.extensions.yui.calendar.DateTimeField
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Component>, IEventSink, IEventSource, IClusterable, IConverterLocator, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<java.lang.String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>
Direct Known Subclasses:
DateField, TimeField

public class DateTimeField
extends FormComponentPanel<java.util.Date>

Works on a Date object. Displays a date field and a DatePicker, a field for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field depends on the time format of this DateTimeField's Locale, as does the visibility of the AM/PM field (see use12HourFormat()).

Author:
eelcohillenius
See Also:
for a variant with just the date field and date picker, Serialized Form

Nested Class Summary
static class DateTimeField.AM_PM
          Enumerated type for different ways of handling the render part of requests.
 
Field Summary
protected static java.lang.String AM_OR_PM_CHOICE
           
protected static java.lang.String DATE
           
protected static java.lang.String HOURS
           
protected static java.lang.String MINUTES
           
 
Fields inherited from class org.apache.wicket.markup.html.form.FormComponent
FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL, VALUE_SEPARATOR
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
DateTimeField(java.lang.String id)
          Construct.
DateTimeField(java.lang.String id, IModel<java.util.Date> model)
          Construct.
 
Method Summary
static java.util.Date changeTimeZone(java.util.Date date, java.util.TimeZone zone)
          Change a date in another timezone
protected  void configure(java.util.Map<java.lang.String,java.lang.Object> widgetProperties)
          Gives overriding classes the option of adding (or even changing/ removing) configuration properties for the javascript widget.
protected  void convertInput()
          Sets the converted input, which is an instance of Date, possibly null.
 DateTimeField.AM_PM getAmOrPm()
          Gets the amOrPm model object of the drop down choice.
protected  java.util.TimeZone getClientTimeZone()
          Gets the client's time zone.
 java.util.Date getDate()
          Gets the date model object for the date TextField.
protected  DateTextField getDateTextField()
           
 java.lang.Integer getHours()
          Gets the hours model object for the TextField
 java.lang.String getInput()
          Gets the request parameter for this component as a string.
 java.lang.Integer getMinutes()
          Gets the minutes model object for the TextField
protected  DatePicker newDatePicker()
          The DatePicker that gets added to the DateTimeField component.
protected  DateTextField newDateTextField(java.lang.String id, PropertyModel<java.util.Date> dateFieldModel)
          create a new DateTextField instance to be added to this panel.
protected  void onBeforeRender()
          Called just before a component is rendered.
 void setAmOrPm(DateTimeField.AM_PM amOrPm)
          Sets the amOrPm model object associated with the drop down choice.
 void setDate(java.util.Date date)
          Sets the date model object associated with the date TextField.
 void setHours(java.lang.Integer hours)
          Sets hours.
 void setMinutes(java.lang.Integer minutes)
          Sets minutes.
protected  boolean use12HourFormat()
          Checks whether the current Locale uses the 12h or 24h time format.
 
Methods inherited from class org.apache.wicket.markup.html.form.FormComponentPanel
checkRequired, newMarkupSourcingStrategy, onComponentTag
 
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, clearInput, convertValue, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInputAsArray, getInputName, getModel, getModelObject, getModelValue, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isInputNullable, isMultiPart, isRequired, isValid, newValidatable, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, remove, setConvertedInput, setLabel, setModel, setModelObject, setModelValue, setRequired, setType, shouldTrimInput, trim, updateCollectionModel, updateModel, valid, validate, validateRequired, validateValidators, visitComponentsPostOrder, visitFormComponentsPostOrder
 
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
getLabel, setLabelInternal
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, hasAssociatedMarkup, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onMarkupAttached, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markRendering, modelChanged, modelChanging, onAfterRender, onConfigure, onEvent, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATE

protected static final java.lang.String DATE
See Also:
Constant Field Values

HOURS

protected static final java.lang.String HOURS
See Also:
Constant Field Values

MINUTES

protected static final java.lang.String MINUTES
See Also:
Constant Field Values

AM_OR_PM_CHOICE

protected static final java.lang.String AM_OR_PM_CHOICE
See Also:
Constant Field Values
Constructor Detail

DateTimeField

public DateTimeField(java.lang.String id)
Construct.

Parameters:
id -

DateTimeField

public DateTimeField(java.lang.String id,
                     IModel<java.util.Date> model)
Construct.

Parameters:
id -
model -
Method Detail

getDateTextField

protected final DateTextField getDateTextField()
Returns:
The date TextField

getAmOrPm

public final DateTimeField.AM_PM getAmOrPm()
Gets the amOrPm model object of the drop down choice.

Returns:
amOrPm

getDate

public final java.util.Date getDate()
Gets the date model object for the date TextField. Any associated time information will be ignored.

Returns:
date

getHours

public final java.lang.Integer getHours()
Gets the hours model object for the TextField

Returns:
hours

getMinutes

public final java.lang.Integer getMinutes()
Gets the minutes model object for the TextField

Returns:
minutes

configure

protected void configure(java.util.Map<java.lang.String,java.lang.Object> widgetProperties)
Gives overriding classes the option of adding (or even changing/ removing) configuration properties for the javascript widget. See the widget's documentation for the available options. If you want to override/ remove properties, you should call super.configure(properties) first. If you don't call that, be aware that you will have to call #localize(Map) manually if you like localized strings to be added.

Parameters:
widgetProperties - the current widget properties

getInput

public java.lang.String getInput()
Description copied from class: FormComponent
Gets the request parameter for this component as a string.

Overrides:
getInput in class FormComponent<java.util.Date>
Returns:
The value in the request for this component

setAmOrPm

public final void setAmOrPm(DateTimeField.AM_PM amOrPm)
Sets the amOrPm model object associated with the drop down choice.

Parameters:
amOrPm - amOrPm

setDate

public final void setDate(java.util.Date date)
Sets the date model object associated with the date TextField. It does not affect hours or minutes.

Parameters:
date - date

setHours

public final void setHours(java.lang.Integer hours)
Sets hours.

Parameters:
hours - hours

setMinutes

public final void setMinutes(java.lang.Integer minutes)
Sets minutes.

Parameters:
minutes - minutes

getClientTimeZone

protected java.util.TimeZone getClientTimeZone()
Gets the client's time zone.

Returns:
The client's time zone or null

convertInput

protected void convertInput()
Sets the converted input, which is an instance of Date, possibly null. It combines the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it.

Note that overriding this method is a better option than overriding FormComponent.updateModel() like the first versions of this class did. The reason for that is that this method can be used by form validators without having to depend on the actual model being updated, and this method is called by the default implementation of FormComponent.updateModel() anyway (so we don't have to override that anymore).

Overrides:
convertInput in class FormComponent<java.util.Date>
See Also:
IConverterLocator, Application.newConverterLocator()

newDateTextField

protected DateTextField newDateTextField(java.lang.String id,
                                         PropertyModel<java.util.Date> dateFieldModel)
create a new DateTextField instance to be added to this panel.

Parameters:
id - the component id
dateFieldModel - model that should be used by the DateTextField
Returns:
a new date text field instance

onBeforeRender

protected void onBeforeRender()
Description copied from class: Component
Called just before a component is rendered.

NOTE: If you override this, you *must* call super.onBeforeRender() within your implementation. Because this method is responsible for cascading Component.onBeforeRender() call to its children it is strongly recommended that super call is made at the end of the override.

Overrides:
onBeforeRender in class Component
See Also:
Component.onBeforeRender()

changeTimeZone

public static java.util.Date changeTimeZone(java.util.Date date,
                                            java.util.TimeZone zone)
Change a date in another timezone

Parameters:
date - The input date.
zone - The target timezone.
Returns:
A new converted date.

use12HourFormat

protected boolean use12HourFormat()
Checks whether the current Locale uses the 12h or 24h time format. This method can be overridden to e.g. always use 24h format.

Returns:
true, if the current Locale uses the 12h format.
false, otherwise

newDatePicker

protected DatePicker newDatePicker()
The DatePicker that gets added to the DateTimeField component. Users may override this method with a DatePicker of their choice.

Returns:
a new DatePicker instance


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.