On Tue, 24 May 2011 13:33:48 -0300, <jackkuros...@w9z.org> wrote:

Hm... I've used this before when I ALWAYS want a field to be required, but I didn't see a way to make a field required or not required based on conditions that are only known when the page is rendered.


@Inject FieldValidatorSource and use its FieldValidator createValidators(Field field, String specification) method to generate a FieldValidator. Then create a FieldValidator getValidator() method using createValidators() and add t:validate="prop:validator" to your TextField.

Example (taken from http://tapestry.1045711.n5.nabble.com/Validation-based-on-condition-td2435565.html):

@Inject
private FieldValidatorSource source;

@InjectComponent
private Field yourField;

public FieldValidator getDynamicConstraints() {
        return source.createValidators(yourField, "required", null);
}

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to