Thanks for that fantastic reply. Yes, in fact, the Component annotation is exactly what I was missing. Don't know why I didn't see it before... And that Input Validate page you refered me to is quite a help. Reading avidly.

Thanks!

Marc

----- Original Message ----- From: "lasitha" <[EMAIL PROTECTED]>
To: "Tapestry users" <users@tapestry.apache.org>
Sent: Saturday, September 29, 2007 19:40
Subject: Re: T5 form field validation, component injection


Hello Marc,

I think you want the @Component annotation instead of
@InjectComponent.  The latter is "Used exclusively inside a mixin to
connect the mixin to the component to which it is attached."[1]

I haven't tested whether this will solve your problem, but it seems likely.

A good starting point for basic form validation is probably the 'Input
Validation' page of the online documentation[2].  It comes with a
simple example and a lot of useful info.

As an aside, you can use Form.recordError() as a convenience around
getDefaultTracker().getErrors().add().

HTH.  Cheers,
lasitha.

[1] http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/InjectComponent.html
[2]
http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html


On 9/29/07, Marc A. Donis <[EMAIL PROTECTED]> wrote:
Hi all,

I am trying to understand how to implement custom validation of form fields.
Here's what I've got so far:

CreateAccount.java:

public class CreateAccount {
    @InjectComponent
    private Form createAccountForm;

    @OnEvent(value = "validate", component = "createAccountForm")
    void validate() throws ValidationException {
        log.debug("validate");
        if (password == null || !password.equals(password2)) {

createAccountForm.getDefaultTracker().getErrors().add("passwords
don't match");
        }
    }
}

and CreateAccount.html:

 <t:form t:id="createAccountForm">
  <t:errors/>
     <t:passwordfield t:id="password" t:validate="required,minLength=4"/>
     <t:passwordfield t:id="password2" t:validate="required"/>
... etc


This is failing because Tapestry is trying to cast CreateAccount to Form...
but why?  Am I going about this all wrong?  What am I missing here?

I feel a bit like I am stumbling around in the dark. Does anybody know of
some T5 examples I can look at, just to get me going?

tia,
Marc


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to