...
Code Block | ||||
---|---|---|---|---|
| ||||
public class Login { @Persist private String userName; private String password; @Inject private UserAuthenticator authenticator; @Component(id = "password") private PasswordField passwordField; @Component private Form form; String onSuccess/** * Do the cross-field validation */ void onValidateFromLoginForm() { 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."); Invalid user name or password."); } } /** * Validation passed, so we'll go to the return null; "PostLogin" page */ Object } onSuccess() { return "PostLogin"; } public String getPassword() { return password; } public void setPassword(String password) { password = password; } public String getUserName() { return userName; } public void setUserName(String userName) { userName = userName; } } |
Wiki Markup |
---|
{float:right|width=40%} {info} Note that the onValidateFromLoginForm() and onSuccess() methodmethods isare 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} |
...
Code Block | ||||
---|---|---|---|---|
| ||||
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> <head> <title>Login</title> </head> <body> <h1>Please Login</h1> <form t:type="form" t:id="formloginForm"> <t:errors/> <t:label for="userName"/>: <input t:type="TextField" t:id="userName" t:validate="required,minlength=3" size="30"/> <br/> <t:label for="password"/>: <input t:type="PasswordField" t:id="password" t:validate="required,minlength=3" size="30"/> <br/> <input type="submit" value="Login"/> </form> </body> </html> |
...
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 | 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="9579a100fddab672-d4094c77-49bb4048-976bb8dc-4bc42cf010fa4a4a40932610"><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 | |
...