Class DatePicker
java.lang.Object
org.apache.wicket.behavior.Behavior
org.wicketstuff.datetime.extensions.yui.calendar.DatePicker
- All Implemented Interfaces:
Serializable,IComponentAwareEventSink,IComponentAwareHeaderContributor,IClusterable
Pops up a YUI calendar component so that the user can select a date. On selection, the date is
set in the component it is coupled to, after which the popup is closed again. This behavior can
only be used with components that either implement
To use, simply add a new instance to your component, which would typically a TextField, like
The CalendarNavigator can be configured by overriding
AbstractTextComponent.ITextFormatProvider or that use
DateConverter configured with an instance of SimpleDateFormat (like Wicket's
default configuration has).To use, simply add a new instance to your component, which would typically a TextField, like
DateTextField.The CalendarNavigator can be configured by overriding
configure(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map) and setting the
property or by returning true for enableMonthYearSelection().- Author:
- eelcohillenius
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterRender(Component component) protected booleanWhether to position the date picker relative to the trigger icon.protected booleanautoHide()Indicates whether the calendar should be hidden when the user clicks on an area of the document outside of the dialog.voidprotected StringThe string to use for the close button label.protected voidconfigure(Map<String, Object> widgetProperties, IHeaderResponse response, Map<String, Object> initVariables) Gives overriding classes the option of adding (or even changing/ removing) configuration properties for the javascript widget.protected booleanIndicates whether plain text is rendered or two select boxes are used to allow direct selection of month and year.protected final String[]filterEmpty(String[] stringArray) Filter all empty elements (workaround forDateFormatSymbolsreturning arrays with empty elements).protected StringOverride this method to further customize the YUI Calendar with additional JavaScript code.protected final StringGets the id of the component that the calendar widget will get attached to.protected StringGets the date pattern to use for putting selected values in the coupled component.protected final StringGets the escaped DOM id that the calendar widget will get attached to.protected intgetFirstDayOfWeek(Locale locale) Gets the first day of week of a given locale.protected CharSequenceGets the icon alt text for the datepicker iconprotected final StringGets the id of the icon that triggers the popup.protected StringGets the style of the icon that triggers the popup.protected CharSequenceGets the title attribute of the datepicker iconprotected CharSequenceGets the url for the popup button.protected LocaleGets the locale that should be used to configure this widget.protected booleanIndicates whether the calendar should be hidden after a date was selected.protected booleanControls whether or not datepicker will contribute YUI libraries to the page as part of its rendering lifecycle.booleanprotected voidlocalize(Map<String, Object> widgetProperties, IHeaderResponse response, Map<String, Object> initVariables) Configure the localized strings for the datepicker widget.protected booleanWhether to notify the associated component when a date is selected.voidrenderHead(Component component, IHeaderResponse response) protected voidrenderHeadInit(IHeaderResponse response) Renders yui & wicket calendar js module loading.protected booleanIndicates whether the calendar should be rendered after it has been loaded.setAutoHide(boolean autoHide) voidsetCloseLabel(String closeLabel) setShowOnFieldClick(boolean show) protected booleanIndicates whether the calendar should be shown when corresponding text input is clicked.protected final String[]Makes a copy of the provided array and for each element copy the substring 0..len to the new arrayprotected final String[]Makes a copy of the provided array and for each element copy the substring 0..len to the new arrayMethods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListener, detach, getStatelessHint, isTemporary, onAttribute, onComponentTag, onConfigure, onEvent, onException, onRemove, onTag, unbind
-
Field Details
-
FORMAT_DATE
Format to be used when configuring YUI calendar. Can be used when using the "selected" property. -
FORMAT_PAGEDATE
For specifying which page (month/year) to show in the calendar, use this format for the date. This is to be used together with the property "pagedate"
-
-
Constructor Details
-
DatePicker
public DatePicker()Construct.
-
-
Method Details
-
bind
-
afterRender
- Overrides:
afterRenderin classBehavior
-
includeYUILibraries
protected boolean includeYUILibraries()Controls whether or not datepicker will contribute YUI libraries to the page as part of its rendering lifecycle. There may be cases when the user wants to use their own version of YUI contribution code, in those cases this method should be overridden to returnfalse.- Returns:
- a flag whether to contribute YUI libraries to the page.
trueby default.
-
renderHead
- Specified by:
renderHeadin interfaceIComponentAwareHeaderContributor- Overrides:
renderHeadin classBehavior
-
renderHeadInit
Renders yui & wicket calendar js module loading. It is done only once per page.- Parameters:
response- header response
-
alignWithIcon
protected boolean alignWithIcon()Whether to position the date picker relative to the trigger icon.- Returns:
- If true, the date picker is aligned with the left position of the icon, and with the top right under. If false, the date picker will skip positioning and will let you do the positioning yourself. Returns true by default.
-
configure
protected void configure(Map<String, Object> widgetProperties, IHeaderResponse response, Map<String, Object> initVariables) 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 calllocalize(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)manually if you like localized strings to be added.- Parameters:
widgetProperties- the current widget propertiesresponse- the header responseinitVariables- variables passed to the Wicket.DateTime.init() js method
-
filterEmpty
Filter all empty elements (workaround forDateFormatSymbolsreturning arrays with empty elements).- Parameters:
stringArray- array to filter- Returns:
- filtered array (without null or empty string elements)
-
getComponentMarkupId
Gets the id of the component that the calendar widget will get attached to.- Returns:
- The DOM id of the component
-
getDatePattern
Gets the date pattern to use for putting selected values in the coupled component.- Returns:
- The date pattern
-
getEscapedComponentMarkupId
Gets the escaped DOM id that the calendar widget will get attached to. All non word characters (\W) will be removed from the string.- Returns:
- The DOM id of the calendar widget - same as the component's markup id + 'Dp'}
-
getIconId
Gets the id of the icon that triggers the popup.- Returns:
- The id of the icon
-
getIconStyle
Gets the style of the icon that triggers the popup.- Returns:
- The style of the icon, e.g. 'cursor: point' etc.
-
getIconTitle
Gets the title attribute of the datepicker icon- Returns:
- text
-
getIconAltText
Gets the icon alt text for the datepicker icon- Returns:
- text
-
getIconUrl
Gets the url for the popup button. Users can override to provide their own icon URL.- Returns:
- the url to use for the popup button/ icon
-
getLocale
Gets the locale that should be used to configure this widget.- Returns:
- By default the locale of the bound component.
-
localize
protected void localize(Map<String, Object> widgetProperties, IHeaderResponse response, Map<String, Object> initVariables) Configure the localized strings for the datepicker widget. This implementation usesDateFormatSymbolsand some slight string manipulation to get the strings for months and week days. Also, the first week day is set according to theLocalereturned bygetLocale(). It should work well for most locales.This method is called from
configure(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)and can be overridden if you want to customize setting up the localized strings but are happy with the rest ofconfigure(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)'s behavior. Note that you can call (overridable) methodgetLocale()to get the locale that should be used for setting up the widget.See YUI Calendar's German and Japanese examples for more info.
- Parameters:
widgetProperties- the current widget propertiesresponse- the header responseinitVariables- variables passed to the Wicket.DateTime.init() js method
-
getFirstDayOfWeek
Gets the first day of week of a given locale.- Returns:
- By default the first day of week accordingly to Calendar class.
-
notifyComponentOnDateSelected
protected boolean notifyComponentOnDateSelected()Whether to notify the associated component when a date is selected. Notifying is done by calling the associated component's onchange JavaScript event handler. You can for instance attach anAjaxEventBehaviorto that component to get a call back to the server. The default is true.- Returns:
- if true, notifies the associated component when a date is selected
-
substring
Makes a copy of the provided array and for each element copy the substring 0..len to the new array- Parameters:
array- array to copy fromlen- size of substring for each element to copy- Returns:
- copy of the array filled with substrings.
-
substring
Makes a copy of the provided array and for each element copy the substring 0..len to the new array- Parameters:
array- array to copy fromstart- start position of the substringlen- size of substring for each element to copy- Returns:
- copy of the array filled with substrings.
-
enableMonthYearSelection
protected boolean enableMonthYearSelection()Indicates whether plain text is rendered or two select boxes are used to allow direct selection of month and year.- Returns:
trueif select boxes should be rendered to allow month and year selection.
falseto render just plain text.
-
hideOnSelect
protected boolean hideOnSelect()Indicates whether the calendar should be hidden after a date was selected.- Returns:
true(default) if the calendar should be hidden after the date selection
falseif the calendar should remain visible after the date selection.
-
showOnFieldClick
protected boolean showOnFieldClick()Indicates whether the calendar should be shown when corresponding text input is clicked.- Returns:
true
false(default)
-
setShowOnFieldClick
- Parameters:
show- a flag indicating whether to show the picker on click event- Returns:
thisinstance to be able to chain calls
-
autoHide
protected boolean autoHide()Indicates whether the calendar should be hidden when the user clicks on an area of the document outside of the dialog.- Returns:
true
false(default)
-
setAutoHide
- Parameters:
autoHide- a flag indicating whether to hide the picker on click event- Returns:
thisinstance to be able to chain calls
-
closeLabel
The string to use for the close button label.- Returns:
- label
-
setCloseLabel
- Parameters:
closeLabel- The string to use for the close button label.
-
renderOnLoad
protected boolean renderOnLoad()Indicates whether the calendar should be rendered after it has been loaded.- Returns:
trueif the calendar should be rendered after it has been loaded.
false(default) if it's initially hidden.
-
getAdditionalJavaScript
Override this method to further customize the YUI Calendar with additional JavaScript code. The code returned by this method is executed right after the Calendar has been constructed and initialized. To refer to the actual Calendar DOM object, use${calendar}in your code.
See the widget's documentation for more information about the YUI Calendar.
Example:protected String getAdditionalJavaScript() { return "${calendar}.addRenderer(\"10/3\", ${calendar}.renderCellStyleHighlight1);"; }- Returns:
- a String containing additional JavaScript code
-
isEnabled
-