You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin Carel <ma...@pricerunner.com> on 2006/02/08 16:27:39 UTC

Server-side validation and form listeners

Hi folks!

I have a problem involving validation and submit listeners.


Here is the (simplified) HTML template:

<form jwcid="@Form" 
listener="ognl:listeners.onChangeEventPropertySelectionListener" 
delegate="bean:delegate">
  <select jwcid="countryChooser@PropertySelection" id="countrySelect" 
value="ognl:country" model="ognl:countriesModel" 
onChange="this.form.submit()"/>

  <span jwcid="@FieldLabel" field="component:pickupDatePicker"/></span>
  <span jwcid="pickupDatePicker"/>
  <input type="submit" listener="ognl:listeners.searchSubmitListener" 
jwcid="@Submit" value="Search"/>
</form>


Here is the spec:

<component id="pickupDatePicker" type="DatePicker">
  <binding name="validators" value="ognl:{beans.required,beans.maxDate}"/>
  <binding name="value" value="ognl:pickupDate"/>
  <binding name="displayName" value="literal:Pick up date"/>
</component>

<bean name="delegate" class="com.utils.MyValidationDelegate" 
property="delegate"/>

<bean name="required" class="org.apache.tapestry.form.validator.Required"/>
<bean name="maxDate" class="org.apache.tapestry.form.validator.MaxDate">
  <set name="maxDate" value="new java.util.Date()">
  </set>
</bean>


And MyValidationDelegate is exactly (apart from the package name) the 
class on 
http://jakarta.apache.org/tapestry/UsersGuide/validation.html#validation.delegate

This code worked great until I wanted to support server-side validation. 
As I understand, server-side validation is only possible with the 
listener specified in the @Form component (and *not* with the one 
specified in the @Submit component). But I was using the listener 
belonging to the @Form for my onChange event of my @PropertySelection 
component, and using the listener belonging to the @Submit for the 
actual form submission.

Is there a simple way to have the form to be submitted with a specific 
listener on my onChange event of my @PropertySelection, and also to have 
my submit button calling the "regular" listener (the one specified in 
the @Form component?

I tried to add a (hidden) @Submit component, which would be clicked via 
JS on the onChange event of my @PropertySelection, but not only the 
listener for that @Submit component is called, but *also* the listener 
defined in the @Form component :(

Note: returning the same page in the first listener (associated with the 
@Submit component) didn't work out, the other listener is also called!

I'm stuck.

/Martin


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


Re: Server-side validation and form listeners

Posted by Martin Carel <ma...@pricerunner.com>.
Hi!

Thanks for the reply. Using the selected and tag parameters worked out 
for me. Now, I do something like:

public void submitListener(IRequestCycle cycle) {

        // act according to how the form was submitted
        if (!getWasSubmittedFromSubmitButton()) {
            processOnChangeEvent(cycle);
            return;
        }

        //process the regular form submit
}

Again, thanks for the hint.

/Martin


Shing Hing Man wrote:
>> Is there a simple way to have the form to be
>> submitted with a specific 
>> listener on my onChange event of my
>> @PropertySelection, and also to have 
>> my submit button calling the "regular" listener (the
>> one specified in 
>> the @Form component?
>>     
>
> I do not know whether there is a simple way of doing
> the above. But have you trying using the paramaters
> selected and tag in the submit component ?
>
> http://jakarta.apache.org/tapestry/tapestry/ComponentReference/Submit.html
>
> With them, you can distinquish in your form listener
> onChangeEventPropertySelectionListener, whether 
> the form submission is triggered by a change in
> PropertSelection or the submit button has been
> clicked. Once you know how the form submission is
> triggered, you can act accordingly.
>
> Shing
>
>  
>
> --- Martin Carel <ma...@pricerunner.com> wrote:
>
>   
>> Hi folks!
>>
>> I have a problem involving validation and submit
>> listeners.
>>
>>
>> Here is the (simplified) HTML template:
>>
>> <form jwcid="@Form" 
>>
>>     
> listener="ognl:listeners.onChangeEventPropertySelectionListener"
>   
>> delegate="bean:delegate">
>>   <select jwcid="countryChooser@PropertySelection"
>> id="countrySelect" 
>> value="ognl:country" model="ognl:countriesModel" 
>> onChange="this.form.submit()"/>
>>
>>   <span jwcid="@FieldLabel"
>> field="component:pickupDatePicker"/></span>
>>   <span jwcid="pickupDatePicker"/>
>>   <input type="submit"
>> listener="ognl:listeners.searchSubmitListener" 
>> jwcid="@Submit" value="Search"/>
>> </form>
>>
>>
>> Here is the spec:
>>
>> <component id="pickupDatePicker" type="DatePicker">
>>   <binding name="validators"
>> value="ognl:{beans.required,beans.maxDate}"/>
>>   <binding name="value" value="ognl:pickupDate"/>
>>   <binding name="displayName" value="literal:Pick up
>> date"/>
>> </component>
>>
>> <bean name="delegate"
>> class="com.utils.MyValidationDelegate" 
>> property="delegate"/>
>>
>> <bean name="required"
>>
>>     
> class="org.apache.tapestry.form.validator.Required"/>
>   
>> <bean name="maxDate"
>> class="org.apache.tapestry.form.validator.MaxDate">
>>   <set name="maxDate" value="new java.util.Date()">
>>   </set>
>> </bean>
>>
>>
>> And MyValidationDelegate is exactly (apart from the
>> package name) the 
>> class on 
>>
>>     
> http://jakarta.apache.org/tapestry/UsersGuide/validation.html#validation.delegate
>   
>> This code worked great until I wanted to support
>> server-side validation. 
>> As I understand, server-side validation is only
>> possible with the 
>> listener specified in the @Form component (and *not*
>> with the one 
>> specified in the @Submit component). But I was using
>> the listener 
>> belonging to the @Form for my onChange event of my
>> @PropertySelection 
>> component, and using the listener belonging to the
>> @Submit for the 
>> actual form submission.
>>
>> Is there a simple way to have the form to be
>> submitted with a specific 
>> listener on my onChange event of my
>> @PropertySelection, and also to have 
>> my submit button calling the "regular" listener (the
>> one specified in 
>> the @Form component?
>>
>> I tried to add a (hidden) @Submit component, which
>> would be clicked via 
>> JS on the onChange event of my @PropertySelection,
>> but not only the 
>> listener for that @Submit component is called, but
>> *also* the listener 
>> defined in the @Form component :(
>>
>> Note: returning the same page in the first listener
>> (associated with the 
>> @Submit component) didn't work out, the other
>> listener is also called!
>>
>> I'm stuck.
>>
>> /Martin
>>
>>
>>
>>     
> ---------------------------------------------------------------------
>   
>> To unsubscribe, e-mail:
>> tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> tapestry-user-help@jakarta.apache.org
>>
>>
>>     
>
>
> Home page :
>   http://uk.geocities.com/matmsh/index.html
>
>
> 	
> 	
> 		
> ___________________________________________________________ 
> Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>   


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


Re: Server-side validation and form listeners

Posted by Shing Hing Man <ma...@yahoo.com>.
> Is there a simple way to have the form to be
> submitted with a specific 
> listener on my onChange event of my
> @PropertySelection, and also to have 
> my submit button calling the "regular" listener (the
> one specified in 
> the @Form component?

I do not know whether there is a simple way of doing
the above. But have you trying using the paramaters
selected and tag in the submit component ?

http://jakarta.apache.org/tapestry/tapestry/ComponentReference/Submit.html

With them, you can distinquish in your form listener
onChangeEventPropertySelectionListener, whether 
the form submission is triggered by a change in
PropertSelection or the submit button has been
clicked. Once you know how the form submission is
triggered, you can act accordingly.

Shing

 

--- Martin Carel <ma...@pricerunner.com> wrote:

> Hi folks!
> 
> I have a problem involving validation and submit
> listeners.
> 
> 
> Here is the (simplified) HTML template:
> 
> <form jwcid="@Form" 
>
listener="ognl:listeners.onChangeEventPropertySelectionListener"
> 
> delegate="bean:delegate">
>   <select jwcid="countryChooser@PropertySelection"
> id="countrySelect" 
> value="ognl:country" model="ognl:countriesModel" 
> onChange="this.form.submit()"/>
> 
>   <span jwcid="@FieldLabel"
> field="component:pickupDatePicker"/></span>
>   <span jwcid="pickupDatePicker"/>
>   <input type="submit"
> listener="ognl:listeners.searchSubmitListener" 
> jwcid="@Submit" value="Search"/>
> </form>
> 
> 
> Here is the spec:
> 
> <component id="pickupDatePicker" type="DatePicker">
>   <binding name="validators"
> value="ognl:{beans.required,beans.maxDate}"/>
>   <binding name="value" value="ognl:pickupDate"/>
>   <binding name="displayName" value="literal:Pick up
> date"/>
> </component>
> 
> <bean name="delegate"
> class="com.utils.MyValidationDelegate" 
> property="delegate"/>
> 
> <bean name="required"
>
class="org.apache.tapestry.form.validator.Required"/>
> <bean name="maxDate"
> class="org.apache.tapestry.form.validator.MaxDate">
>   <set name="maxDate" value="new java.util.Date()">
>   </set>
> </bean>
> 
> 
> And MyValidationDelegate is exactly (apart from the
> package name) the 
> class on 
>
http://jakarta.apache.org/tapestry/UsersGuide/validation.html#validation.delegate
> 
> This code worked great until I wanted to support
> server-side validation. 
> As I understand, server-side validation is only
> possible with the 
> listener specified in the @Form component (and *not*
> with the one 
> specified in the @Submit component). But I was using
> the listener 
> belonging to the @Form for my onChange event of my
> @PropertySelection 
> component, and using the listener belonging to the
> @Submit for the 
> actual form submission.
> 
> Is there a simple way to have the form to be
> submitted with a specific 
> listener on my onChange event of my
> @PropertySelection, and also to have 
> my submit button calling the "regular" listener (the
> one specified in 
> the @Form component?
> 
> I tried to add a (hidden) @Submit component, which
> would be clicked via 
> JS on the onChange event of my @PropertySelection,
> but not only the 
> listener for that @Submit component is called, but
> *also* the listener 
> defined in the @Form component :(
> 
> Note: returning the same page in the first listener
> (associated with the 
> @Submit component) didn't work out, the other
> listener is also called!
> 
> I'm stuck.
> 
> /Martin
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 


Home page :
  http://uk.geocities.com/matmsh/index.html


	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

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