Reputation: 5281
I'm using Tapestry 4.
I have several TextFields whose values get passed into Strings in the page class, and they work great as long as there is some content in the fields. Most of them are optional, so I believe I can use the StringTranslator
with empty=
in that case, but for a couple of fields for which a value is required, I'm having a hard time getting validation to work.
I expected a simple required
validator to work:
<component id="myRequiredField" type="TextField">
<binding name="value" value="ognl:stringValue" />
<binding name="validators" value="validators:required" />
</component>
Failing that, I expected minLength
to work:
<component id="myRequiredField" type="TextField">
<binding name="value" value="ognl:stringValue" />
<binding name="validators" value="validators:required,minLength=1" />
</component>
Both attempts at validation allow the value as retrieved with getStringValue()
to be null upon form submission. My Form
and Submit
components look like:
<component id="myUpdateForm" type="Form">
<binding name="delegate" value="beans.validationDelegate" />
</component>
<component id="submitUpdate" type="Submit">
<binding name="action" value="listener:doUpdate" />
</component>
Upvotes: 0
Views: 332
Reputation: 5281
It turns out that the validation was working, but I wasn't checking whether my validation delegate had errors before operating on the incoming data. The following seems to be the correct approach to take in any listener that depends on validation, given the setup as listed in the question:
@Bean
public abstract ValidationDelegate getValidationDelegate();
public void doUpdate() {
if (!getValidationDelegate().getHasErrors()) {
// business logic
}
}
Upvotes: 1