You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Kevin C. Dorff" <ke...@dorffweb.com> on 2008/04/21 21:15:54 UTC

T5: question about onValidate and form reset

Sorry if these have been covered, I am somewhat new to T5, using 5.0.11.

First, onValidate seems to be called once for each form variable, BEFORE the
setter is called for that form variable. While I understand that logic, it
SEEMS makes things a touch difficult to check the value I want to validate,
especially if I want to validate several variables at once, such as if I
want to validate two password variables to make sure they are equal, or to
verify a login page. I can do something like

   onValidateFromPassword(String newPassword)

and the assume username was already validated and "set" and then try
"newPassword" for the user. This just seems awkward. Is it really
intentional that onValidate is called once per form variable and before each
setter? I would prefer that all setters are called, the onValidate is called
so I can check stuff. Really not sure how this is best to be coded.

SECOND: if I want a form reset as a submit button to reset the state of the
form (all my fields are @Persist), if I have validation on the fields,
pressing "Reset" will trigger Javascript validation and not allow the
submit. I looked at the Component Reference on submit and don't see a way to
short-circuit validation so I can perform the reset, and start nice and
fresh.
-- 
View this message in context: http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16809659.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: question about onValidate and form reset

Posted by Robert Zeigler <ro...@scazdl.org>.
On Apr 21, 2008, at 4/212:15 PM , Kevin C. Dorff wrote:
>
> Sorry if these have been covered, I am somewhat new to T5, using  
> 5.0.11.
>
> First, onValidate seems to be called once for each form variable,  
> BEFORE the
> setter is called for that form variable. While I understand that  
> logic, it
> SEEMS makes things a touch difficult to check the value I want to  
> validate,
> especially if I want to validate several variables at once, such as  
> if I
> want to validate two password variables to make sure they are equal,  
> or to
> verify a login page. I can do something like
>
>   onValidateFromPassword(String newPassword)
>
> and the assume username was already validated and "set" and then try
> "newPassword" for the user. This just seems awkward. Is it really
> intentional that onValidate is called once per form variable and  
> before each
> setter? I would prefer that all setters are called, the onValidate  
> is called
> so I can check stuff. Really not sure how this is best to be coded.
>

Sounds like what you really want is to just do:

onValidateFromForm() {
   ...
}

That will be called after all of the other setters, and all of the  
other validation constraints have been applied, and is the best place  
for doing things like:

   if(!equal(_password,_newpassword)) {
     ...
   }

(where equal is some null-safe equals method).


> SECOND: if I want a form reset as a submit button to reset the state  
> of the
> form (all my fields are @Persist), if I have validation on the fields,
> pressing "Reset" will trigger Javascript validation and not allow the
> submit. I looked at the Component Reference on submit and don't see  
> a way to
> short-circuit validation so I can perform the reset, and start nice  
> and
> fresh.

Well...
There's probably a "right" way to do this (but it's been a long while  
since I've dealt with a similar problem, and there wasn't a way back  
then).
So the way I kludged around this, was to do something like:

<input t:type="submit" value="Reset"  
onclick="this.form.onsubmit=null;"/>

The trick is that onsubmit is the function that calls all of the  
javascript validation. So you can clear all of that out by setting it  
to null, and the form will still submit fine.
I haven't used this for a "reset" button, but I've used it for cancel  
buttons, where I need to cancel the form and return to some other  
page, but I also need to clear out saved state, etc.

Robert

>
> -- 
> View this message in context: http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16809659.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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


Re: T5: question about onValidate and form reset

Posted by Thiago HP <th...@gmail.com>.
On 4/23/08, Thiago HP <th...@gmail.com> wrote:

> You can use the @OnEvent(component = "componentName",
>  value="eventName") annotation
>  (http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/annotations/OnEvent.html)
>  instead of method name conventions and then you can name your method
>  any way suits you best. I prefer this than using name conventions, as
>  a single typo and  a name convention fails.

More info here:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/event.html.

-- 
Thiago

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


Re: T5: question about onValidate and form reset

Posted by Thiago HP <th...@gmail.com>.
On 4/22/08, Kevin C. Dorff <ke...@dorffweb.com> wrote:

>  NOW, to help with some future questions: With T3/T4 it was pretty easy to
>  determine what methods to use for what, just look at the objects I was
>  extending or implementing and I could see what method to implement or
>  override to get what functionality. But since T5 uses POJO's, I am left
>  trying to discover methods like
>
>    onSubmit
>    onValidateForm
>    onValidateFromPassword
>    onSelectedFromResetButton

You can use the @OnEvent(component = "componentName",
value="eventName") annotation
(http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/annotations/OnEvent.html)
instead of method name conventions and then you can name your method
any way suits you best. I prefer this than using name conventions, as
a single typo and  a name convention fails.

-- 
Thiago

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


Re: T5: question about onValidate and form reset

Posted by Peter Beshai <pe...@gmail.com>.
I don't know of an extensive all-in-one-place list, but the documentation is
full of information about them all-- if you know where to look :-)

For Form related events, you're most likely interested in validating input:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html --
includes a detailed breakdown of what happens under the Form component
heading

Other components that trigger events usually specify the event name they
trigger in their JavaDocs, if not on their component reference pages.

For page related phases, you may want to check out the Page Lifecycle page:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/lifecycle.html --
at the bottom mentions 3 possible methods

For component related phases, you will want to see the Component Rendering
page:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/rendering.html


Peter Beshai

On Tue, Apr 22, 2008 at 11:02 AM, Kevin C. Dorff <ke...@dorffweb.com> wrote:

>
> Thanks for these suggestions. First Robert Zeigler, onValidateForm is
> exactly
> what I needed, also I found the null-safe comparison was important.
>
> Second, your suggest about disabling the submit javascript handler was
> right
> on. The missing piece I put together was that my onValidateForm is always
> going to be called but when I added the "onSelectedFromResetButton()"
> handler for my reset button, I just did a registrationForm.clearErrors();
> to
> clear any errors - as after a reset there shouldn't be any errors.
>
> NOW, to help with some future questions: With T3/T4 it was pretty easy to
> determine what methods to use for what, just look at the objects I was
> extending or implementing and I could see what method to implement or
> override to get what functionality. But since T5 uses POJO's, I am left
> trying to discover methods like
>
>   onSubmit
>   onValidateForm
>   onValidateFromPassword
>   onSelectedFromResetButton
>
> some of these are intuitive, some are absolutely not. Is there a source
> that
> just talks about for Pages, Services, Forms, Form Buttons, etc. all the
> method names (format of method names) Tapestry will try to evoke, their
> order, when, etc? Sometimes it seem that the component reference is
> explicit
> on this, often (such as onValidate) it seems the component reference
> doesn't
> mention these at all - or maybe I just am missing something.
>
> Thanks! Loving Tapestry5 so far (when I am not stumped).
> Kevin
> --
> View this message in context:
> http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16824702.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: question about onValidate and form reset

Posted by "Kevin C. Dorff" <ke...@dorffweb.com>.
Thanks for these suggestions. First Robert Zeigler, onValidateForm is exactly
what I needed, also I found the null-safe comparison was important.

Second, your suggest about disabling the submit javascript handler was right
on. The missing piece I put together was that my onValidateForm is always
going to be called but when I added the "onSelectedFromResetButton()"
handler for my reset button, I just did a registrationForm.clearErrors(); to
clear any errors - as after a reset there shouldn't be any errors.

NOW, to help with some future questions: With T3/T4 it was pretty easy to
determine what methods to use for what, just look at the objects I was
extending or implementing and I could see what method to implement or
override to get what functionality. But since T5 uses POJO's, I am left
trying to discover methods like

   onSubmit
   onValidateForm
   onValidateFromPassword
   onSelectedFromResetButton

some of these are intuitive, some are absolutely not. Is there a source that
just talks about for Pages, Services, Forms, Form Buttons, etc. all the
method names (format of method names) Tapestry will try to evoke, their
order, when, etc? Sometimes it seem that the component reference is explicit
on this, often (such as onValidate) it seems the component reference doesn't
mention these at all - or maybe I just am missing something.

Thanks! Loving Tapestry5 so far (when I am not stumped).
Kevin
-- 
View this message in context: http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16824702.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: question about onValidate and form reset

Posted by Robert Zeigler <ro...@scazdl.org>.
Whoops... Peter is correct about the method/event name:  
onValidateForm. Not onValidateFromForm, as I had posted, sorry.

Robert

On Apr 21, 2008, at 4/212:40 PM , Peter Beshai wrote:
> You want to use onValidateForm to handle validation that involves  
> more than
> one field.
>
> Seems like the simplest solution to your second problem is to use an
> actionlink instead of a submit button and just have the fields reset  
> by the
> event handler. I believe t5-components has a button component that  
> will give
> you the same look and feel of the submit button, without submitting  
> the
> form.
>
> Peter Beshai
>
> On Mon, Apr 21, 2008 at 3:15 PM, Kevin C. Dorff <ke...@dorffweb.com>  
> wrote:
>
>>
>> Sorry if these have been covered, I am somewhat new to T5, using  
>> 5.0.11.
>>
>> First, onValidate seems to be called once for each form variable,  
>> BEFORE
>> the
>> setter is called for that form variable. While I understand that  
>> logic, it
>> SEEMS makes things a touch difficult to check the value I want to
>> validate,
>> especially if I want to validate several variables at once, such as  
>> if I
>> want to validate two password variables to make sure they are  
>> equal, or to
>> verify a login page. I can do something like
>>
>>  onValidateFromPassword(String newPassword)
>>
>> and the assume username was already validated and "set" and then try
>> "newPassword" for the user. This just seems awkward. Is it really
>> intentional that onValidate is called once per form variable and  
>> before
>> each
>> setter? I would prefer that all setters are called, the onValidate is
>> called
>> so I can check stuff. Really not sure how this is best to be coded.
>>
>> SECOND: if I want a form reset as a submit button to reset the  
>> state of
>> the
>> form (all my fields are @Persist), if I have validation on the  
>> fields,
>> pressing "Reset" will trigger Javascript validation and not allow the
>> submit. I looked at the Component Reference on submit and don't see  
>> a way
>> to
>> short-circuit validation so I can perform the reset, and start nice  
>> and
>> fresh.
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16809659.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>


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


Re: T5: question about onValidate and form reset

Posted by Peter Beshai <pe...@gmail.com>.
You want to use onValidateForm to handle validation that involves more than
one field.

Seems like the simplest solution to your second problem is to use an
actionlink instead of a submit button and just have the fields reset by the
event handler. I believe t5-components has a button component that will give
you the same look and feel of the submit button, without submitting the
form.

Peter Beshai

On Mon, Apr 21, 2008 at 3:15 PM, Kevin C. Dorff <ke...@dorffweb.com> wrote:

>
> Sorry if these have been covered, I am somewhat new to T5, using 5.0.11.
>
> First, onValidate seems to be called once for each form variable, BEFORE
> the
> setter is called for that form variable. While I understand that logic, it
> SEEMS makes things a touch difficult to check the value I want to
> validate,
> especially if I want to validate several variables at once, such as if I
> want to validate two password variables to make sure they are equal, or to
> verify a login page. I can do something like
>
>   onValidateFromPassword(String newPassword)
>
> and the assume username was already validated and "set" and then try
> "newPassword" for the user. This just seems awkward. Is it really
> intentional that onValidate is called once per form variable and before
> each
> setter? I would prefer that all setters are called, the onValidate is
> called
> so I can check stuff. Really not sure how this is best to be coded.
>
> SECOND: if I want a form reset as a submit button to reset the state of
> the
> form (all my fields are @Persist), if I have validation on the fields,
> pressing "Reset" will trigger Javascript validation and not allow the
> submit. I looked at the Component Reference on submit and don't see a way
> to
> short-circuit validation so I can perform the reset, and start nice and
> fresh.
> --
> View this message in context:
> http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16809659.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>