Class StrutsHtmlConstraintProvider
- All Implemented Interfaces:
HtmlConstraintProvider
HtmlConstraintProvider.
Governed by one rule: never false-reject. A constraint is emitted only when the browser cannot
reject input the server would accept. In particular this implementation never sets or changes
an input's type — switching a field to type="number" would reject
1234,50, which the framework's locale-aware conversion accepts in a comma-decimal locale,
and the browsers' email/url grammars differ from the framework's validators.
Range constraints are therefore emitted only on a control the developer already made numeric, or
date.
- Since:
- 7.4.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConstraints(Map<String, String> attributes, Validator validator, HtmlControlType control, Object value) protected voidaddDateRange(Map<String, String> attributes, RangeValidatorSupport<?> validator) Ajava.util.Datebound becomes its calendar date in the default time zone, the zone the submittedyyyy-MM-ddis parsed in.protected voidaddDoubleRange(Map<String, String> attributes, DoubleRangeFieldValidator validator, HtmlControlType control) protected voidaddLength(Map<String, String> attributes, StringLengthFieldValidator validator, HtmlControlType control) protected voidprotected voidaddPattern(Map<String, String> attributes, RegexFieldValidator validator, HtmlControlType control) protected voidaddRange(Map<String, String> attributes, RangeValidatorSupport<?> validator, HtmlControlType control) protected voidaddRequiredField(Map<String, String> attributes, RequiredFieldValidator validator, HtmlControlType control, Object value) requiredfails only on null, an empty array or an empty collection.protected voidaddRequiredString(Map<String, String> attributes, HtmlControlType control) requiredstringfails on null, empty and (by default) blank, so the browser'srequiredcan only reject what the server would also reject.protected voidaddTemporalRequired(Map<String, String> attributes, HtmlControlType control, Class<?> propertyType) An empty temporal input submits"", which the built-in converters turn into null for the typesconvertsBlankToNull(Class)accepts, sorequiredthen fails on both sides.protected voidadmitBlankInPattern(Map<String, String> attributes) RegexFieldValidatorskips a value that trims to empty before it looks attrim, while the browser skipspatternonly for the empty string.constraintsFor(List<Validator> validators, HtmlControlType control, Object action, Object value) constraintsFor(List<Validator> validators, HtmlControlType control, Object action, Object value, Class<?> propertyType) What the framework calls.protected booleanconvertsBlankToNull(Class<?> propertyType) A property with its own converter that maps""to a value needs a provider overriding this.protected booleanrejectsBlank(List<Validator> validators) Only a trimmingrequiredstringfails a whitespace-only value server-side; withtrim=falseit counts as non-empty and falls through to the other validators.
-
Constructor Details
-
StrutsHtmlConstraintProvider
public StrutsHtmlConstraintProvider()
-
-
Method Details
-
constraintsFor
public Map<String,String> constraintsFor(List<Validator> validators, HtmlControlType control, Object action, Object value) - Specified by:
constraintsForin interfaceHtmlConstraintProvider- Parameters:
validators- the field's validators; may be null or emptycontrol- the kind of control being renderedaction- the object the field's validators run against, used to resolve i18n validator messages: the action, or the visited object for a field reached through avisitorvalidator; may be nullvalue- the field's current value as the tag resolved it — what the page renders and, for a control that omits its parameter when left empty, what the server will validate on such a submit; may be null- Returns:
- attribute name to value; never null, possibly empty
-
constraintsFor
public Map<String,String> constraintsFor(List<Validator> validators, HtmlControlType control, Object action, Object value, Class<?> propertyType) Description copied from interface:HtmlConstraintProviderWhat the framework calls. The default ignorespropertyTypeand delegates toHtmlConstraintProvider.constraintsFor(List, HtmlControlType, Object, Object), so a provider written against 7.4.0 keeps working unchanged.- Specified by:
constraintsForin interfaceHtmlConstraintProviderpropertyType- the declared type of the property the field binds to; null when it cannot be resolved
-
rejectsBlank
Only a trimmingrequiredstringfails a whitespace-only value server-side; withtrim=falseit counts as non-empty and falls through to the other validators. -
admitBlankInPattern
RegexFieldValidatorskips a value that trims to empty before it looks attrim, while the browser skipspatternonly for the empty string. Unless another validator on the field rejects blank input, the pattern therefore gets a whitespace-only alternative so that a single space is not blocked client-side and accepted server-side. -
addConstraints
-
addRequiredString
requiredstringfails on null, empty and (by default) blank, so the browser'srequiredcan only reject what the server would also reject. Safe on any text-entry control. -
addRequiredField
protected void addRequiredField(Map<String, String> attributes, RequiredFieldValidator validator, HtmlControlType control, Object value) requiredfails only on null, an empty array or an empty collection. A control that submits an empty string rather than omitting the parameter therefore passes server-side while the browser blocks it — an empty text input, a select with an empty-valued header option, and an unticked checkbox (CheckboxInterceptor substitutes "false") are all in that group. Only RADIO and FILE omit the parameter entirely when empty, so only they agree with the browser here; temporal controls are decided by property type inaddTemporalRequired(java.util.Map<java.lang.String, java.lang.String>, org.apache.struts2.components.HtmlControlType, java.lang.Class<?>).An omitted parameter leaves the property at whatever it already holds, which is the value being rendered — a primitive's 0, or what
prepare()loaded. The validator itself decides whether that value would fail, so the attribute is emitted only when the two sides agree on it. -
addTemporalRequired
protected void addTemporalRequired(Map<String, String> attributes, HtmlControlType control, Class<?> propertyType) An empty temporal input submits"", which the built-in converters turn into null for the typesconvertsBlankToNull(Class)accepts, sorequiredthen fails on both sides.- Since:
- 7.5.0
-
convertsBlankToNull
A property with its own converter that maps""to a value needs a provider overriding this.- Since:
- 7.5.0
-
addDateRange
Ajava.util.Datebound becomes its calendar date in the default time zone, the zone the submittedyyyy-MM-ddis parsed in. Dropping the time leaves the browser no stricter than the server: a min of 10:00 on the 1st still lets the 1st through client-side.- Since:
- 7.5.0
-
addLength
protected void addLength(Map<String, String> attributes, StringLengthFieldValidator validator, HtmlControlType control) -
addPattern
protected void addPattern(Map<String, String> attributes, RegexFieldValidator validator, HtmlControlType control) -
addRange
protected void addRange(Map<String, String> attributes, RangeValidatorSupport<?> validator, HtmlControlType control) -
addDoubleRange
protected void addDoubleRange(Map<String, String> attributes, DoubleRangeFieldValidator validator, HtmlControlType control) -
addMessage
-