Class WPartialDateField
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WPartialDateField
-
- All Implemented Interfaces:
AjaxTarget
,AjaxTrigger
,BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Diagnosable
,Disableable
,Input
,Labelable
,Mandatable
,SubordinateTarget
,SubordinateTrigger
,WComponent
,WebComponent
,Serializable
public class WPartialDateField extends AbstractInput implements AjaxTrigger, AjaxTarget, SubordinateTrigger, SubordinateTarget
This component is a date entry component. Individual themes may add features such as automatic text formatting and date picker widgets. Convenience methods exist to set and get the value as a java date object.
"Partial dates" can be specified without day or month components, e.g. "JAN 2001", or just "2001".
When the component is bound to a bean, the bean property must be a string containing the date in the format "yyyyMMdd". Parts of the date that do not have a value are padded with space characters by default. The padding character can be changed using the
setPaddingChar(char)
method. An example of a partial date bean value for "Mar 2012" would be "201203". Note, trailing spaces are removed. If a padding character of '@' was specified, then the bean value would be "201203@@".- Author:
- Ming Gao, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WPartialDateField.PartialDateFieldModel
Holds the extrinsic state information of the partial date.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractInput
AbstractInput.InputModel
-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WPartialDateField()
Creates a WPartialDateField with no date specified.WPartialDateField(char paddingChar)
Creates a WPartialDateField with a specific padding character.WPartialDateField(Integer day, Integer month, Integer year)
Creates a WPartialDateField with the specified date.WPartialDateField(Integer day, Integer month, Integer year, char paddingChar)
Creates a WPartialDateField with the specified date and padding character.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
doHandleRequest(Request request)
Specific handle request processing for an input component is provided here.protected WPartialDateField.PartialDateFieldModel
getComponentModel()
Returns the effective component model for this component.Date
getDate()
Returns the java date value, else null if the value cannot be parsed.Integer
getDay()
Returns the day of the month value.Integer
getMonth()
Returns the month value.protected WPartialDateField.PartialDateFieldModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.char
getPaddingChar()
The padding character used in the partial date value.String
getPartialDate()
Get the partial date as its formatted string.String
getRequestValue(Request request)
Provide the value of the component on the Request.String
getText()
Retrieves the text as entered by the user.String
getValue()
Provide the value of the component returned byDataBound.getData()
in the correct format.String
getValueAsString()
Retrieves a String representation of the date field's value.Integer
getYear()
Returns the year value.protected void
handleRequestValue(String value, boolean valid, String text)
Set the request value.boolean
isValidDate()
Indicates whether the text value held in this field is a valid date.protected WPartialDateField.PartialDateFieldModel
newComponentModel()
Creates a new component model appropriate for this component.void
setData(Object data)
Sets the data that this component displays/edits.void
setDate(Date date)
Set the WPartialDateField with the given java date.void
setInvalidDateErrorMessage(String message)
Sets the validation error message.void
setPaddingChar(char paddingChar)
Deprecated.will be removed so padding character is immutablevoid
setPartialDate(Integer day, Integer month, Integer year)
Set the WPartialDateField with the given day, month and year.protected void
validateComponent(List<Diagnostic> diags)
Override WInput's validateComponent to perform further validation on the date.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractInput
addValidator, beforeHandleRequest, createMandatoryDiagnostic, doHandleChanged, getActionCommand, getActionObject, getActionOnChange, getDefaultSubmitButton, getDiagnostics, getValidators, handleRequest, isChangedInLastRequest, isCurrentAjaxTrigger, isDisabled, isEmpty, isMandatory, isPresent, isReadOnly, setActionObject, setActionOnChange, setChangedInLastRequest, setDefaultSubmitButton, setDisabled, setMandatory, setMandatory, setReadOnly, showErrorIndicatorsForComponent, showIndicatorsForComponent, showWarningIndicatorsForComponent, toString
-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContext, tidyUpUIContextForTree, validate, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanAware
getBean, getBeanProperty, getBeanValue, setBeanProperty
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanBound
isSearchAncestors, setBean
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanProviderBound
getBeanId, setBeanId, setBeanProvider
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Constructor Detail
-
WPartialDateField
public WPartialDateField()
Creates a WPartialDateField with no date specified.
-
WPartialDateField
public WPartialDateField(char paddingChar)
Creates a WPartialDateField with a specific padding character. The padding character used in the partial date value. The default padding character is a space. If the padding character is a space, then the date value will be right trimmed to remove the trailing spaces.- Parameters:
paddingChar
- the padding character used in the partial date value.
-
WPartialDateField
public WPartialDateField(Integer day, Integer month, Integer year)
Creates a WPartialDateField with the specified date.- Parameters:
day
- A number from 1 to 31 or null if unknown.month
- A number from 1 to 12, or null if unknown.year
- A number, or null if unknown.
-
WPartialDateField
public WPartialDateField(Integer day, Integer month, Integer year, char paddingChar)
Creates a WPartialDateField with the specified date and padding character.- Parameters:
day
- A number from 1 to 31 or null if unknown.month
- A number from 1 to 12, or null if unknown.year
- A number, or null if unknown.paddingChar
- the padding character used in the partial date value.
-
-
Method Detail
-
setPartialDate
public void setPartialDate(Integer day, Integer month, Integer year)
Set the WPartialDateField with the given day, month and year. Each of the day, month and year parameters that make up the partial date are optional.- Parameters:
day
- A number from 1 to 31 or null if unknown.month
- A number from 1 to 12, or null if unknown.year
- A number, or null if unknown.
-
getPaddingChar
public char getPaddingChar()
The padding character used in the partial date value. The default padding character is a space. If the padding character is a space, then the date value will be right trimmed to remove the trailing spaces.- Returns:
- the padding character used in the partial date value
-
setPaddingChar
@Deprecated public void setPaddingChar(char paddingChar)
Deprecated.will be removed so padding character is immutableThe padding character used in the partial date value. The default padding character is a space. If the padding character is a space, then the date value will be right trimmed to remove the trailing spaces.- Parameters:
paddingChar
- the padding character used in the partial date value.
-
doHandleRequest
protected boolean doHandleRequest(Request request)
Specific handle request processing for an input component is provided here.Input components are required to determine if the component has changed in the request, set the component data to the new value (if changed) and return the changed flag.
- Specified by:
doHandleRequest
in classAbstractInput
- Parameters:
request
- the request being responded to.- Returns:
- true if the input component has changed, otherwise return false
-
handleRequestValue
protected void handleRequestValue(String value, boolean valid, String text)
Set the request value.- Parameters:
value
- the date valuevalid
- true if valid valuetext
- the user text
-
getRequestValue
public String getRequestValue(Request request)
Provide the value of the component on the Request.If the component is not on the request, the components current value will be provided.
- Specified by:
getRequestValue
in interfaceInput
- Parameters:
request
- the request being responded to.- Returns:
- the value of this component on the Request, or its current state if it is not on the request.
-
setInvalidDateErrorMessage
public void setInvalidDateErrorMessage(String message)
Sets the validation error message.- Parameters:
message
- The errorMessage to set, or null to use the default error message.
-
validateComponent
protected void validateComponent(List<Diagnostic> diags)
Override WInput's validateComponent to perform further validation on the date. A partial date is invalid if there was text submitted but no date components were parsed.- Overrides:
validateComponent
in classAbstractInput
- Parameters:
diags
- the list into which any validation diagnostics are added.
-
setDate
public void setDate(Date date)
Set the WPartialDateField with the given java date.- Parameters:
date
- the date
-
getValue
public String getValue()
Provide the value of the component returned byDataBound.getData()
in the correct format.If required, this method can convert the data into the correct type and also do any validation before the value is used.
- Specified by:
getValue
in interfaceInput
- Overrides:
getValue
in classAbstractInput
- Returns:
- the value of the component returned by
DataBound.getData()
in the correct format.
-
getPartialDate
public String getPartialDate()
Get the partial date as its formatted string.The expected format of the partial date is "yyyyMMdd", where parts of the date that do not have a value are padded with the padding character.
- Returns:
- the partial data formatted as a string, or null
-
setData
public void setData(Object data)
Sets the data that this component displays/edits. For bean aware components, this should only be called from handleRequest to set user-entered data.- Specified by:
setData
in interfaceDataBound
- Overrides:
setData
in classWBeanComponent
- Parameters:
data
- the data to set
-
getDay
public Integer getDay()
Returns the day of the month value.- Returns:
- the day of the month, or null if unspecified.
-
getMonth
public Integer getMonth()
Returns the month value.- Returns:
- the month, or null if unspecified.
-
getYear
public Integer getYear()
Returns the year value.- Returns:
- the year, or null if unspecified.
-
getDate
public Date getDate()
Returns the java date value, else null if the value cannot be parsed.- Returns:
- the java date or null
-
getText
public String getText()
Retrieves the text as entered by the user. This is not necessarily a valid date.- Returns:
- the text, as entered by the user.
-
isValidDate
public boolean isValidDate()
Indicates whether the text value held in this field is a valid date.- Returns:
- true if the field contains text which is a valid date, false otherwise.
-
getValueAsString
public String getValueAsString()
Retrieves a String representation of the date field's value. The date value will be returned using its default String representation.- Specified by:
getValueAsString
in interfaceInput
- Overrides:
getValueAsString
in classAbstractInput
- Returns:
- the date value, or the text entered by the user if there is no valid date.
-
newComponentModel
protected WPartialDateField.PartialDateFieldModel newComponentModel()
Creates a new component model appropriate for this component.- Overrides:
newComponentModel
in classAbstractInput
- Returns:
- a new PartialDateFieldModel.
-
getComponentModel
protected WPartialDateField.PartialDateFieldModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModel
in classAbstractInput
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WPartialDateField.PartialDateFieldModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModel
in classAbstractInput
- Returns:
- the model for this component
-
-