public class DateIntervalValidator extends AbstractIntervalValidator<Date>
ContentValidator
validates the content by comparing one or more couple of date values.
For each couple of values, the identified end date should be greater than or equal to the identified start date.
The start and end dates to compare are identified in validator's configuration by the metadata path as follows:
<startDate path="path/to/metadata/start"/>
<endDate path="path/to/metadata/end"/>
If the path of metadata can contain one or more repeaters.Constructor and Description |
---|
DateIntervalValidator() |
Modifier and Type | Method and Description |
---|---|
protected void |
addErrorEmpty(Errors errors,
MetadataDefinition minDefinition,
MetadataDefinition maxDefinition,
I18nizableText emptyLabel)
Add an error when the max or the min value is empty but the interval is mandatory
|
protected void |
addIntervalError(Errors errors,
MetadataDefinition minDefinition,
MetadataDefinition maxDefinition,
Date startDate,
Date endDate)
Add an error when the max value is less than the min value
|
protected String |
configureMaxPath(Configuration configuration)
Get the metadata max path from the configuration
|
protected String |
configureMinPath(Configuration configuration)
Get the metadata min path from the configuration
|
protected SimpleField<Date> |
getEmptyValue()
Get a value holder containing an empty value array.
|
protected SimpleField<Date> |
getValues(Form parentForm,
String fieldName)
Get the values of the field to validate from the form.
|
protected boolean |
isLessThan(Date endDate,
Date startDate)
Test if the first number is less than the second one.
|
protected boolean |
isSupportedType(MetadataType type)
Test if the metadata type is one expected by the validator
|
_validateInterval, configure, service, validate, validate
getContentType, setContentType
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
public DateIntervalValidator()
protected String configureMinPath(Configuration configuration) throws ConfigurationException
AbstractIntervalValidator
configureMinPath
in class AbstractIntervalValidator<Date>
configuration
- The configurationConfigurationException
- If an error occursprotected String configureMaxPath(Configuration configuration) throws ConfigurationException
AbstractIntervalValidator
configureMaxPath
in class AbstractIntervalValidator<Date>
configuration
- The configurationConfigurationException
- If an error occursprotected SimpleField<Date> getValues(Form parentForm, String fieldName)
AbstractIntervalValidator
getValues
in class AbstractIntervalValidator<Date>
parentForm
- The form containing the user values.fieldName
- The field name.protected SimpleField<Date> getEmptyValue()
AbstractIntervalValidator
getEmptyValue
in class AbstractIntervalValidator<Date>
protected boolean isLessThan(Date endDate, Date startDate)
AbstractIntervalValidator
isLessThan
in class AbstractIntervalValidator<Date>
endDate
- The first number to compare.startDate
- The second number to compare.protected boolean isSupportedType(MetadataType type)
AbstractIntervalValidator
isSupportedType
in class AbstractIntervalValidator<Date>
type
- The metadata typeprotected void addIntervalError(Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, Date startDate, Date endDate)
AbstractIntervalValidator
addIntervalError
in class AbstractIntervalValidator<Date>
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionstartDate
- The min valueendDate
- The max valueprotected void addErrorEmpty(Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, I18nizableText emptyLabel)
AbstractIntervalValidator
addErrorEmpty
in class AbstractIntervalValidator<Date>
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionemptyLabel
- The label of the empty field