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.
- Since:
- 7.4.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConstraints(Map<String, String> attributes, Validator validator, HtmlControlType control, Object value) 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 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) 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
-
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.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. -
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
-