You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Prescott <mi...@gmail.com> on 2010/03/17 18:49:20 UTC

How to hook component into validation?

I have a component which is a wrapper around some form fields.  (Imagine an
'edit address' component.)

If I want to provide some custom validation, is there a way to listen to the
enclosing form's validation event?  The problem is that the form is defined
in the page, not in my component. Right now, the page catches the validation
event and then calls a validate(Form form) method on my component.

But I'm wondering if there's a way to have my component do this
automatically, so that future users won't have to remember to hook this up.
(Plus, the page's validation event handler does nothing else, so it's kinda
silly.)

Any tips greatly appreciated!

Michael

Re: How to hook component into validation?

Posted by Michael Prescott <mi...@gmail.com>.
Joost, thanks for your help.

Michael

On Wed, Mar 17, 2010 at 8:27 PM, Joost Schouten (ml)
<jo...@jsportal.com>wrote:

> You can listen for the validation events on the individual form elements of
> your component.
>
> eg:
>
> @Enviromental
> private ValidationTracker validationTracker;
>
> @OnEvent(component = "myFormField", value = EventConstants.VALIDATE)
> private void validateFormField(Object valueAboutToBeSet) {
>   //do your validation and record errors where needed with the
> validationTracker
> }
>
> Hope this helps,
> Joost
>
>
> Michael Prescott wrote:
>
>> I have a component which is a wrapper around some form fields.  (Imagine
>> an
>> 'edit address' component.)
>>
>> If I want to provide some custom validation, is there a way to listen to
>> the
>> enclosing form's validation event?  The problem is that the form is
>> defined
>> in the page, not in my component. Right now, the page catches the
>> validation
>> event and then calls a validate(Form form) method on my component.
>>
>> But I'm wondering if there's a way to have my component do this
>> automatically, so that future users won't have to remember to hook this
>> up.
>> (Plus, the page's validation event handler does nothing else, so it's
>> kinda
>> silly.)
>>
>> Any tips greatly appreciated!
>>
>> Michael
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: How to hook component into validation?

Posted by "Joost Schouten (ml)" <jo...@jsportal.com>.
You can listen for the validation events on the individual form elements 
of your component.

eg:

@Enviromental
private ValidationTracker validationTracker;

@OnEvent(component = "myFormField", value = EventConstants.VALIDATE)
private void validateFormField(Object valueAboutToBeSet) {
    //do your validation and record errors where needed with the 
validationTracker
}

Hope this helps,
Joost

Michael Prescott wrote:
> I have a component which is a wrapper around some form fields.  (Imagine an
> 'edit address' component.)
>
> If I want to provide some custom validation, is there a way to listen to the
> enclosing form's validation event?  The problem is that the form is defined
> in the page, not in my component. Right now, the page catches the validation
> event and then calls a validate(Form form) method on my component.
>
> But I'm wondering if there's a way to have my component do this
> automatically, so that future users won't have to remember to hook this up.
> (Plus, the page's validation event handler does nothing else, so it's kinda
> silly.)
>
> Any tips greatly appreciated!
>
> Michael
>
>   


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