Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected error in onValidateXXX method example

...

Code Block
java
java
public class Login
{
    @Persist
    @Property
    private String userName;

    @Property
    private String password;

    @Inject
    private UserAuthenticator authenticator;

    @InjectComponent(id = "password")
    private PasswordField passwordField;

    @Component
    private Form form;

    /**
     * Do the cross-field validation
     */
    void onValidateFromFormonValidateFromLoginForm()
    {
        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.class;
    }
}

...

Validator

Constraint Type

Description

Example

email

Ensures that the given input looks like a valid e-mail address

<t:textfield value="email" validate="email" />

max

long

Enforces a maximum integer value

<t:textfield value="age" validate="max=120,min=0" />

maxLength

int

Makes sure that a string value has a maximum length

<t:textfield value="zip" validate="maxlength=7" />

min

long

Enforces a minimum integer value

<t:textfield value="age" validate="max=120,min=0" />

minLength

int

Makes sure that a string value has a minimum length

<t:textfield value="somefield" validate="minlength=1" />

none

Does nothing (used to override a @Validate annotation)

<t:textfield value="somefield" validate="none" />

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d22f35ed1fe9dd96-3e7867bc-4a6145b5-98da8441-a2176dd39490d0a306de263c"><ac:plain-text-body><![CDATA[

regexp

pattern

Makes sure that a string value conforms to a given pattern

<t:textfield value="letterfield" validate="regexp=^[A-Za-z]+$" />

]]></ac:plain-text-body></ac:structured-macro>

required

Makes sure that a string value is not null and not the empty string

<t:textfield value="name" validate="required" />

...