Class DatePicker

All Implemented Interfaces:
Animatable<DatePicker>, CanDrop<DatePicker>, Clickable<DatePicker>, SupportAppend<DatePicker>, SupportHelpIcon<DatePicker>, SupportPlaceholder<DatePicker>, Draggable<DatePicker>, Editable<DatePicker>, Focusable<DatePicker>, HandleHotKey<DatePicker>, HandleKeyboardEvents<DatePicker>, HandleMouseEvents<DatePicker>, Touchable<DatePicker>

Date picker form item>

The date picker form element is for inputting a date and/or time. With this component, the user can input a date and/or time, using a dropdown calendar. This ensures that the format of the date will be correct.

Supported events:

AnimationStart AnimationEnd, Focus FocusOut FocusIn LosesFocus copy cut EnterPressed input paste Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, KeyPress, KeyUp, KeyDown, TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd HotKey

Since:
4.0
Author:
JBStrap
  • Constructor Details

    • DatePicker

      public DatePicker(String name, String label)
      Creates a date picker input field with the specified name and label.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      Throws:
      NullPointerException - If the name is null
    • DatePicker

      public DatePicker(String name, String label, String language)
      Creates a date picker item, with the specified name and label, and the specified language code.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      language - The language code, that the form item will use. If not specified, or null, the framework will use the default language. The default language can be set with the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter.
      Throws:
      NullPointerException - If the name is null
    • DatePicker

      public DatePicker(String name, String label, String language, String dateFormat)
      Creates a date picker item, with the specified name, label, date format and the specified language code.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      language - The language code, that the form item will use. If not specified, or null, the framework will use the default language. The default language can be set with the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter.
      dateFormat - The date format to be used when displaying a date. If not specified, the default format will be used, which can be specified using the JBStrapParamType.DATE_FORMAT JBStrap parameter.
      Throws:
      NullPointerException - If the name is null
    • DatePicker

      public DatePicker(DataDescriptorColumn column)

      Createts a date picker item, based on the specified DataDescriptor column.

      The method creates and sets the date picker item, based on the DataDescriptor column, specified in the parameters. The following parameters from the DataDescriptor column are used:

      • DataDecriptorColumn.getTitle - The title set in the DataDescriptor column will be used by the input field as its label.
      • DataDescriptorColumn.isNullable() - If the field can a null value, the field will be marked as not mandatory. If it cannot have a null value, the field will be marked as mandatory.
      • MetaParamName.DATE_FORMAT - The date format to be used when displaying a date. If not specified, the default format will be used, which can be specified using the JBStrapParamType.DATE_FORMAT and JBStrapParamType.DATETIME_FORMAT JBStrap parameters.
      • MetaParamName.PLACEHOLDER - This text will be used as a placeholder.
      • MetaParamName.SIZE - The value specified here defines the size of the input field. (Applicable values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The value specified here defines the state of the input field. (Applicable values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here defines the field's default value. The value must have the type of field, in this case, it must be a boolean value.
      • MetaParamName.READ_ONLY - If true, the field will be read only. Otherwise, the field can have its contents modified by the user.
      • MetaParamName.ENABLED - If false, the field will be disabled (it will be created in an unusable state.) Otherwise, the field will be enabled when created.
      • MetaParamName.HELP - If the parameter is specified, an icon will be displayed next to the field. If the user moves over the icon, the text specified here will be displayed, as a help text.
      • MetaParamName.HELP_ICON - If the icon name is specified (from the Icon enum), then this icon will replace the default "?" icon.
      • MetaParamName.DESCRIPTION - The text specified here will appear below the field, in a smaller, italic font.
      • MetaParamName.TAB_INDEX - The value specified here determines the order of the input focus (when the user presses the Tab key). The order goes in ascending order. If not specified, the component will use the order value from the DataDescriptor. If that not specified either, the order in which it was placed in the DataDescriptor will be used.
      • MetaParamName.SHOW_DROPDOWN - Ezzel a paraméterrel lehet beállítani, hogy a felhasználónak van-e lehetősége az évek és a hónapok közöt lenyíló menüből választani. Alapértelmezés szerint a felhasználónak van lehetősége lenyíló menüből évet és hónapot választani. Ha megadjuk a paramétert, és a paraméter értéke false, akkor a felhasználónak nem lesz lehetősége íly módon választani, csak a naptár felett található előre és hátra lapozással fog tudni váltani a hónapok között.

      Parameters:
      column - The DataDescriptor column, that will be used as a basis for the form item.
      Throws:
      NullPointerException - If the column was specified as null
    • DatePicker

      public DatePicker(DataDescriptorColumn column, String language)

      Createts a date picker item, based on the specified DataDescriptor column and using the specified language code.

      The method creates and sets the date picker item, based on the DataDescriptor column, specified in the parameters. The following parameters from the DataDescriptor column are used:

      • DataDescriptorColumn.getTitle - The title set in the DataDescriptor column will be used by the input field as its label.
      • DataDescriptorColumn.isNullable() - If the field can have a null value, the field will be marked as not mandatory. If it cannot have a null value, the field will be marked as mandatory.
      • MetaParamName.DATE_FORMAT - The date format to be used when displaying a date. If not specified, the default format will be used, which can be specified using the JBStrapParamType.DATE_FORMAT and JBStrapParamType.DATETIME_FORMAT JBStrap parameters.
      • MetaParamName.PLACEHOLDER - This text will be used as a placeholder.
      • MetaParamName.SIZE - The value specified here defines the size of the input field. (Applicable values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The value specified here defines the state of the input field. (Applicable values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here defines the field's default value. The value must have the type of field, in this case, it must be a boolean value.
      • MetaParamName.READ_ONLY - If true, the field will be read only. Otherwise, the field can have its contents modified by the user.
      • MetaParamName.ENABLED - If false, the field will be disabled (it will be created in an unusable state.) Otherwise, the field will be enabled when created.
      • MetaParamName.HELP - If the parameter is specified, an icon will be displayed next to the field. If the user moves over the icon, the text specified here will be displayed, as a help text.
      • MetaParamName.HELP_ICON - If the icon name is specified (from the Icon enum), then this icon will replace the default "?" icon.
      • MetaParamName.DESCRIPTION - The text specified here will appear below the field, in a smaller, italic font.
      • MetaParamName.TAB_INDEX - The value specified here determines the order of the input focus (when the user presses the Tab key). The order goes in ascending order. If not specified, the component will use the order value from the DataDescriptor. If that not specified either, the order in which it was placed in the DataDescriptor will be used.
      • MetaParamName.SHOW_DROPDOWN - Use this parameter to set if the user is allowed to select from the dropdown menu. By default, the user is allowed to select a year and a month from the dropdown menu. If the parameter is specified as false, the user is not allowed to select from the dropdown menu. Month selection is only possible by clicking on the next and previous buttons above the calendar.

      Parameters:
      column - The DataDescriptor column, that will be used as a basis for the form item.
      language - The language code, that the form item will use. If not specified, or null, the framework will use the default language. The default language can be set with the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter.
      Throws:
      NullPointerException - If the column was specified as null
  • Method Details

    • init

      public void init() throws JavaScriptLoadError
      Description copied from class: Component
      The component initialization method.

      Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.

      Overrides:
      init in class FormItem<Date,DatePicker>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • drawEditor

      public void drawEditor(StringWriter writer)
      Description copied from class: FormItem

      Draws the editor component.

      You do not need to use this method during development, but all components extending the form item must implement it. Use the method to generate the input field’s HTML code. This code is then inserted into the corresponding DOM code when drawing the form item.

      Specified by:
      drawEditor in class FormItem<Date,DatePicker>
      Parameters:
      writer - The HTML string writer class instance; write here the HTML code for the input field
    • setDateFormat

      public DatePicker setDateFormat(String dateFormat)
      Sets the component’s date format.
      Parameters:
      dateFormat - The date format used by the component If null is set, the framework’s default date format is used. The framework’s default date format can be set using the JBStrap parameter JBStrapParamType.DATE_FORMAT.
      Returns:
      Date picker component
    • getDateFormat

      public String getDateFormat()
      Gets the component’s date format.
      Returns:
      The date format used by the component
    • setMinimumDate

      public final DatePicker setMinimumDate(Date minDate)
      Sets the minimum date. If specified, the user cannot pick an earlier date. If the user manually inputs a date earlier than the specified minimum date, the date will be automatically modified to the minimum date.
      Parameters:
      minDate - The minimum date
      Returns:
      The date picker component
    • getMinimumDate

      public final Date getMinimumDate()
      Gets the minimum date
      Returns:
      The minimum date or null, if no minimum date was specified
    • setMaximumDate

      public final DatePicker setMaximumDate(Date maxDate)
      Sets the maximum date. If specified, the user cannot pick a later date. If the user manually inputs a date later than the specified maximum date, the date will be automatically modified to the maximum date.
      Parameters:
      maxDate - The maximum date
      Returns:
      The date picker component
    • getMaximumDate

      public final Date getMaximumDate()
      Gets the maximum date
      Returns:
      The maximum date or null, if no maximum date was specified
    • setDropDownPosition

      public DatePicker setDropDownPosition(DropDownPosition position)
      Sets on which side of the input field the dropdown calendar is displayed. By default, the dropdown calendar appears on the left of the input field.
      Parameters:
      position - The position where the dropdown calendar is displayed If null is set, the dropdown calendar is displayed on the left side of the input field.
      Returns:
      Date picker component
    • getDropDownPosition

      public DropDownPosition getDropDownPosition()
      Gets the side of the input field where the dropdown calendar is displayed.
      Returns:
      The position where the dropdown calendar is displayed
    • setShowDropdowns

      public DatePicker setShowDropdowns(boolean show)
      Sets if year and month selection is done by clicking on a dropdown menu. By default, year and month selection is done by clicking on a dropdown menu.
      Parameters:
      show - If true is set, year and month selection is done by clicking on a dropdown menu. If false is set, the user is only allowed to increase or decrease months.
      Returns:
      Date picker component
    • isShowDropdowns

      public boolean isShowDropdowns()
      Checks if the user is allowed to select a year or month by clicking on the dropdown menu.
      Returns:
      If true, the user is allowed to select a year or a month from the dropdown menu. Otherwise, the user is only allowed to step back and forward between months.
    • afterDraw

      public void afterDraw()
      Description copied from class: Component
      The operations to be executed after the drawing of the component

      By default, this is an empty method. It has to be overwritten on a component or page if additional operations have to be executed after the drawing process. One such operation is data retrieval, which shouldn't run in constructors so that the user could see results of an operation or navigation process.

      Overrides:
      afterDraw in class FormItem<Date,DatePicker>
    • setValue

      public DatePicker setValue(Date value)
      Sets the date picker's value.
      Overrides:
      setValue in class FormItem<Date,DatePicker>
      Parameters:
      value - The date picker value
      Returns:
      The date picker component
    • setOriginalValue

      public DatePicker setOriginalValue(Date originalValue)
      Sets the original value of the date picker.
      Overrides:
      setOriginalValue in class FormItem<Date,DatePicker>
      Parameters:
      originalValue - The original value
      Returns:
      The date picker component
    • setObjectValue

      public DatePicker setObjectValue(Object value)
      Description copied from class: FormItem
      Sets the form item’s current value using the object in the parameter.
      Overrides:
      setObjectValue in class FormItem<Date,DatePicker>
      Parameters:
      value - The date picker actual value
      Returns:
      The date picker component
    • setOriginalObjectValue

      public DatePicker setOriginalObjectValue(Object value)
      Description copied from class: FormItem
      Sets the form item’s original value using the object in the parameter.
      Overrides:
      setOriginalObjectValue in class FormItem<Date,DatePicker>
      Parameters:
      value - The date picker original value
      Returns:
      The date picker component
    • setDefaultValue

      public DatePicker setDefaultValue(Object defaultValue)
      Sets the default value of the date picker, based on the specified object.
      The value is interpreted, following these rules:
      • If null, the value will be null
      • If the specified value is a Date type, or extends from it, the object value will be the specified value
      • If not null or not Date type, then the specified value's text format will be converted by the component to fit the date format. If successful, the value will be set and formatted, if not, an exception will be thrown
      Specified by:
      setDefaultValue in class FormItem<Date,DatePicker>
      Parameters:
      defaultValue - The default value of the date picker
      Returns:
      The date picker component
      Throws:
      IllegalArgumentException - If the specified object couldn't be interpreted as a Date
    • getValueAsString

      public String getValueAsString()
      Gets the form item’s current value as String.
      Overrides:
      getValueAsString in class FormItem<Date,DatePicker>
      Returns:
      Current value of the form item in String format
    • setReadOnly

      public DatePicker setReadOnly(boolean readOnly)
      Sets the date picker to read-only mode. By default, the date picker is displayed as writable and the user can freely modify the form item value. If the component is set to read-only mode, the user is unable to modify the date picker value.
      Overrides:
      setReadOnly in class FormItem<Date,DatePicker>
      Parameters:
      readOnly - If true is set, the date picker is switched to read-only mode and the user is unable to modify the value. If false is set, the date picker is switched to writable mode and the user is able to modify form item value.
      Returns:
      Date picker component
    • setEnabled

      public DatePicker setEnabled(boolean enabled)
      Sets the date picker to be enabled. Defaults to true
      Overrides:
      setEnabled in class FormItem<Date,DatePicker>
      Parameters:
      enabled - true, the component is enabled, otherwise it's disabled
      Returns:
      Date picker component
    • prepend

      public DatePicker prepend(Component<?> component)
      Description copied from interface: SupportAppend
      Appends a component before the input field.
      Specified by:
      prepend in interface SupportAppend<DatePicker>
      Parameters:
      component - Component instance If null or is specified, nothing is displayed before the input field.
      Returns:
      Form item component
    • prepend

      public DatePicker prepend(Icon icon)
      Description copied from interface: SupportAppend
      Appends an icon before the input field.
      Specified by:
      prepend in interface SupportAppend<DatePicker>
      Parameters:
      icon - Icon If null is specified, nothing is displayed before the input field. Available icons are listed in the enum Icon.
      Returns:
      Form item component
    • prepend

      public DatePicker prepend(String text)
      Description copied from interface: SupportAppend
      Appends a text before the input field.
      Specified by:
      prepend in interface SupportAppend<DatePicker>
      Parameters:
      text - Appended text If null or an empty string is specified, nothing is displayed before the input field
      Returns:
      Form item component
    • removePrepend

      public DatePicker removePrepend(int index)
      Description copied from interface: SupportAppend
      Removes an object from before the input field using its index. The first item has the index 0.
      Specified by:
      removePrepend in interface SupportAppend<DatePicker>
      Parameters:
      index - Index If a nonexistent index is specified, removal is not successful.
      Returns:
      Form item component
    • append

      public DatePicker append(Component<?> component)
      Description copied from interface: SupportAppend
      Appends a component after the input field.
      Specified by:
      append in interface SupportAppend<DatePicker>
      Parameters:
      component - Component instance If null or is specified, nothing is displayed after the input field.
      Returns:
      Form item component
    • append

      public DatePicker append(Icon icon)
      Description copied from interface: SupportAppend
      Displays an icon after the input field.
      Specified by:
      append in interface SupportAppend<DatePicker>
      Parameters:
      icon - Icon If null or is specified, nothing is displayed after the input field. Available icons are listed in the enum Icon.
      Returns:
      Form item component
    • append

      public DatePicker append(String text)
      Description copied from interface: SupportAppend
      Appends a text after the input field.
      Specified by:
      append in interface SupportAppend<DatePicker>
      Parameters:
      text - Text If null or an empty string is specified, nothing is displayed after the input field.
      Returns:
      Form item component
    • removeAppend

      public DatePicker removeAppend(int index)
      Description copied from interface: SupportAppend
      Removes a component instance from after the input field. The first item’s index is 0.
      Specified by:
      removeAppend in interface SupportAppend<DatePicker>
      Parameters:
      index - Index If a nonexistent index is specified, removal is not successful.
      Returns:
      Form item component