All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent<Date,FormComponent<Date>>, IMetadataContext<Serializable,Component>, IQueueRegion, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
DateField, TimeField

public class DateTimeField extends FormComponentPanel<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()).

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, IModel) and calling FormComponent.processInput():


  DateTimeField dateTimeField = new DateTimeField(...) {
    protected DateTextField newDateTextField(String id, IModel<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;
    }
  }
 
Author:
eelcohillenius
See Also:
  • Field Details

  • Constructor Details

    • DateTimeField

      public DateTimeField(String id)
      Construct.
      Parameters:
      id -
    • DateTimeField

      public DateTimeField(String id, IModel<Date> model)
      Construct.
      Parameters:
      id -
      model -
  • Method Details

    • newHoursTextField

      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.
      Parameters:
      id - the component id
      model - model that should be used by the TextField
      type - the type of the text field
      Returns:
      a new text field instance
    • newMinutesTextField

      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.
      Parameters:
      id - the component id
      model - model that should be used by the TextField
      type - the type of the text field
      Returns:
      a new text field instance
    • getDateTextField

      protected final DateTextField getDateTextField()
      Returns:
      The date TextField
    • getAmOrPm

      public final DateTimeField.AM_PM getAmOrPm()
      Deprecated.
      valid during rendering only
      Gets the amOrPm model object of the drop down choice.
      Returns:
      amOrPm
    • getDate

      public final Date getDate()
      Deprecated.
      valid during rendering only
      Gets the date model object for the date TextField. Any associated time information will be ignored.
      Returns:
      date
    • getHours

      public final Integer getHours()
      Deprecated.
      valid during rendering only
      Gets the hours model object for the TextField
      Returns:
      hours
    • getMinutes

      public final Integer getMinutes()
      Deprecated.
      valid during rendering only
      Gets the minutes model object for the TextField
      Returns:
      minutes
    • configure

      protected void configure(Map<String,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 configure(java.util.Map) manually if you like localized strings to be added.
      Parameters:
      widgetProperties - the current widget properties
    • getInput

      public String getInput()
      Overrides:
      getInput in class FormComponent<Date>
    • 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(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(Integer hours)
      Sets hours.
      Parameters:
      hours - hours
    • setMinutes

      public final void setMinutes(Integer minutes)
      Sets minutes.
      Parameters:
      minutes - minutes
    • getClientTimeZone

      protected TimeZone getClientTimeZone()
      Gets the client's time zone.
      Returns:
      The client's time zone or null
    • convertInput

      public 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<Date>
    • newDateInstance

      protected Date newDateInstance()
      A factory method for the DateTextField's model object.
      Returns:
      any specialization of java.util.Date
    • newDateInstance

      protected Date newDateInstance(long time)
      A factory method for the DateTextField's model object.
      Parameters:
      time - the time in milliseconds
      Returns:
      any specialization of java.util.Date
    • newDateTextField

      protected DateTextField newDateTextField(String id, IModel<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()
      Overrides:
      onBeforeRender in class FormComponent<Date>
      See Also:
    • changeTimeZone

      public static Date changeTimeZone(Date date, 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