...
After the fields have done their processing, the Form emits a "validateFormvalidate" event. This is a chance to perform cross-form validation that can't be described declaratively.
Note: For compatibility with release 5.1 and earlier, the Form component also emits a "validateForm" event. (See TAP5-760.)
Next, the Form determines if there have been any validation errors. If there have been, then the submission is considered a failure, and a "failure" event is emitted. If there have been no validation errors, then a "success" event is emitted.
...
Code Block | ||||
---|---|---|---|---|
| ||||
public class Login { @Persist @Property private String userName; @Property private String password; @Inject private UserAuthenticator authenticator; @Component@InjectComponent(id = "password") private PasswordField passwordField; @Component private Form form; /** * Do the cross-field validation */ void onValidateFromLoginFormonValidateFromForm() { if (!authenticator.isValid(userName, password)) { // record an error, and thereby prevent Tapestry from emitting a "success" event form.recordError(passwordField, "Invalid user name or password."); } } /** * Validation passed, so we'll go to the "PostLogin" page */ Object onSuccess() { return "PostLogin"; } public String getPassword() { return password; } public void setPassword(String password) { password = password; } public String getUserName() { return userName; }*/ publicObject void setUserName(String userNameonSuccess() { userName = userNamereturn PostLogin.class; } } |
Wiki Markup |
---|
{float:right|width=40%} {info} Note that the onValidateFromLoginForm() and onSuccess() methods are not public; event handler methods can have any visibility, even private. Package private (that is, no modifier) is the typical use, as it allows the component to be tested, from a test case class in the same package. {info} {float} |
...
Configuring Fields and Labels
The template for a the Login page contains a minimal amount of Tapestry instrumentation:
...
Validator | Constraint Type | Description | Example | ||
– | Ensures that the given input is a valid e-mail address | | |||
max | long | Enforces a maximum integer value | | ||
maxLength | int | Makes sure that a string value has a maximum length | | ||
min | long | Enforces a minimum integer value | | ||
minLength | int | Does nothing (used to override a @Validate annotation) | | ||
none | – | Makes sure that a string value has a minimum length | | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3e96bbb34334d01e-084a2d88-415241c6-8759bea6-e8c0377e1f1adff025eb1fe1"><ac:plain-text-body><![CDATA[ | regexp | pattern | Makes sure that a string value conforms to a given pattern | | ]]></ac:plain-text-body></ac:structured-macro> |
required | – | Makes sure that a string value is not null and not the empty string | |
...