public class DateTimeField extends FormComponentPanel<Date>
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()
).
Ajaxifying the DateTimeField: If you want to update a DateTimeField with an
AjaxFormComponentUpdatingBehavior
, you have to attach it to the contained
DateTextField
by overriding newDateTextField(String, PropertyModel)
and calling
FormComponent.processInput()
:
DateTimeField dateTimeField = new DateTimeField(...) {
protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
{
DateTextField dateField = super.newDateTextField(id, dateFieldModel);
dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
protected void onUpdate(AjaxRequestTarget target) {
processInput(); // let DateTimeField process input too
...
}
});
return recorder;
}
}
for a variant with just the date field and date picker
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
DateTimeField.AM_PM
Enumerated type for different ways of handling the render part of requests.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
AM_OR_PM_CHOICE |
protected static String |
DATE |
protected static String |
HOURS |
protected static String |
MINUTES |
FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL, VALUE_SEPARATOR
ENABLE, FLAG_AFTER_RENDERING, FLAG_INITIALIZED, FLAG_PREPARED_FOR_RENDER, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RENDERING, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING
Constructor and Description |
---|
DateTimeField(String id)
Construct.
|
DateTimeField(String id,
IModel<Date> model)
Construct.
|
Modifier and Type | Method and Description |
---|---|
static Date |
changeTimeZone(Date date,
TimeZone zone)
Change a date in another timezone
|
protected void |
configure(Map<String,Object> widgetProperties)
Gives overriding classes the option of adding (or even changing/ removing) configuration
properties for the javascript widget.
|
void |
convertInput()
Sets the converted input, which is an instance of
Date , possibly null. |
DateTimeField.AM_PM |
getAmOrPm()
Deprecated.
valid during rendering only
|
protected TimeZone |
getClientTimeZone()
Gets the client's time zone.
|
Date |
getDate()
Deprecated.
valid during rendering only
|
protected DateTextField |
getDateTextField() |
Integer |
getHours()
Deprecated.
valid during rendering only
|
String |
getInput()
Gets the request parameter for this component as a string.
|
Integer |
getMinutes()
Deprecated.
valid during rendering only
|
protected Date |
newDateInstance()
A factory method for the DateTextField's model object.
|
protected Date |
newDateInstance(long time)
A factory method for the DateTextField's model object.
|
protected DatePicker |
newDatePicker()
The DatePicker that gets added to the DateTimeField component.
|
protected DateTextField |
newDateTextField(String id,
PropertyModel<Date> dateFieldModel)
create a new
DateTextField instance to be added to this panel. |
protected TextField<Integer> |
newHoursTextField(String id,
IModel<Integer> model,
Class<Integer> type)
create a new
TextField instance for hours to be added to this panel. |
protected TextField<Integer> |
newMinutesTextField(String id,
IModel<Integer> model,
Class<Integer> type)
create a new
TextField instance for minutes to be added to this panel. |
protected void |
onBeforeRender()
Called just before a component is rendered only if the component is visible.
|
void |
setAmOrPm(DateTimeField.AM_PM amOrPm)
Sets the amOrPm model object associated with the drop down choice.
|
void |
setDate(Date date)
Sets the date model object associated with the date TextField.
|
void |
setHours(Integer hours)
Sets hours.
|
void |
setMinutes(Integer minutes)
Sets minutes.
|
protected boolean |
use12HourFormat()
Checks whether the current
Locale uses the 12h or 24h time format. |
checkRequired, newMarkupSourcingStrategy, onComponentTag
add, add, clearInput, convertValue, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInputAsArray, getInputName, getModel, getModelObject, getModelValue, getParameterValues, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isInputNullable, isMultiPart, isRequired, isValid, newValidatable, newValidationError, onDetach, onDisabled, onInvalid, onRequired, onValid, processChildren, processInput, remove, reportRequiredError, setConvertedInput, setLabel, setModel, setModelObject, setModelValue, setRequired, setType, shouldTrimInput, trim, updateAutoLabels, updateCollectionModel, updateModel, valid, validate, validateRequired, validateValidators, visitComponentsPostOrder, visitFormComponentsPostOrder
getLabel
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onAfterRenderChildren, onComponentTagBody, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, canCallListenerInterfaceAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, 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, 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, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, 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, visitParents, warn, wrap
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
dequeue, getRegionMarkup, newDequeueContext
protected static final String DATE
protected static final String HOURS
protected static final String MINUTES
protected static final String AM_OR_PM_CHOICE
public DateTimeField(String id)
id
- protected TextField<Integer> newHoursTextField(String id, IModel<Integer> model, Class<Integer> type)
TextField
instance for hours to be added to this panel.id
- the component idmodel
- model that should be used by the TextField
type
- the type of the text fieldprotected TextField<Integer> newMinutesTextField(String id, IModel<Integer> model, Class<Integer> type)
TextField
instance for minutes to be added to this panel.id
- the component idmodel
- model that should be used by the TextField
type
- the type of the text fieldprotected final DateTextField getDateTextField()
public final DateTimeField.AM_PM getAmOrPm()
public final Date getDate()
public final Integer getHours()
public final Integer getMinutes()
protected void configure(Map<String,Object> widgetProperties)
configure(java.util.Map)
manually if you like localized strings to be added.widgetProperties
- the current widget propertiespublic String getInput()
FormComponent
getInput
in class FormComponent<Date>
public final void setAmOrPm(DateTimeField.AM_PM amOrPm)
amOrPm
- amOrPmpublic final void setDate(Date date)
date
- datepublic final void setHours(Integer hours)
hours
- hourspublic final void setMinutes(Integer minutes)
minutes
- minutesprotected TimeZone getClientTimeZone()
public void convertInput()
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).
protected Date newDateInstance()
protected Date newDateInstance(long time)
time
- the time in millisecondsprotected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
DateTextField
instance to be added to this panel.id
- the component iddateFieldModel
- model that should be used by the DateTextField
protected void onBeforeRender()
Component
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.
onBeforeRender
in class Component
Component.onBeforeRender()
public static Date changeTimeZone(Date date, TimeZone zone)
date
- The input date.zone
- The target timezone.protected boolean use12HourFormat()
Locale
uses the 12h or 24h time format. This method can be
overridden to e.g. always use 24h format.Locale
uses the 12h format.protected DatePicker newDatePicker()
DatePicker
instanceCopyright © 2006–2021 Apache Software Foundation. All rights reserved.