You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Stavrinides <P....@albourne.com> on 2009/10/06 09:07:53 UTC
Validation question - at which point are property values set before
post
Hi everyone,
I came across what seems a strange scenario to me, using Tapestry 5 validation. I am looking for a little understanding more than anything else with regards to 'the point at which properties values are set, before a form posts'... please examine this code snippet:
//This code works
public void onSuccess() throws SQLException {
if(isTerminated()){
if(personnelData.getEndDate() == null){
employeeform.recordError("End date is required");
return;
}
}
...
}
//And this code doesn't because the property personnelData.getEndDate() appears to not have been set yet!
void onValidateFromEndDate(){
if(isTerminated()){
if(personnelData.getEndDate() == null){
employeeform.recordError("End date is required");
}
}
}
personnelData.getEndDate() evaluates to a date in the onSuccess() method, but in the onValidateFromEndDate validator it is null?? the component in question is a datepicker, so the value is set via JavaScript. I am wandering why Tapestry doesn't pick up the value change until the onSuccess() event triggers.
Thanks,
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Antwort: Validation question - at which point are property values
set before post
Posted by Ulrich Stärk <ul...@spielviel.de>.
Also consider the validateForm event that gets fired before success and after all individual form
fields have been processed. This is the right point for cross-field validation.
Uli
Am 06.10.2009 09:30 schrieb dirk.lattermann@bgs-ag.de:
> Peter Stavrinides <P....@albourne.com> schrieb am 06.10.2009
> 09:07:53:
>
>> Validation question - at which point are property values set before post
>
> They seem to be set after the input field validators complete.
>> //This code works
>> public void onSuccess() throws SQLException {
>>
>> if(isTerminated()){
>> if(personnelData.getEndDate() == null){
>> employeeform.recordError("End date is required");
>> return;
>> }
>> }
>> ...
>> }
>
> On success is fired after the validation succeeded, so the properties are
> set.
>
>> //And this code doesn't because the property personnelData.getEndDate
>> () appears to not have been set yet!
>>
>> void onValidateFromEndDate(){
>> if(isTerminated()){
>> if(personnelData.getEndDate() == null){
>> employeeform.recordError("End date is required");
>> }
>> }
>> }
>
> In the field validators, the corresponding properties are not set yet. You
> can get the value via a parameter:
>
> void onValidateFromEndDate(String theDate) { ... }
>
> If you don't use a String parameter, the type will be coerced to the class
> you specified. I'm not sure which class works best for your endDate, maybe
> void onValidateFromEndDate(Date theDate) { ... }
>
> HTH, Dirk
> BGS Beratungsgesellschaft
> Software Systemplanung AG Niederlassung Köln/Bonn
> Grantham-Allee 2-8
> 53757 Sankt Augustin
> Fon: +49 (0) 2241 / 166-500
> Fax: +49 (0) 2241 / 166-680
> www.bgs-ag.de Geschäftssitz Mainz
> Registergericht
> Amtsgericht Mainz
> HRB 62 50
> Aufsichtsratsvorsitzender
> Klaus Hellwig
> Vorstand
> Hermann Kiefer
> Nils Manegold
> Thomas Reitz
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Antwort: Validation question - at which point are property values set
before post
Posted by di...@bgs-ag.de.
Peter Stavrinides <P....@albourne.com> schrieb am 06.10.2009
09:07:53:
> Validation question - at which point are property values set before post
They seem to be set after the input field validators complete.
>
> //This code works
> public void onSuccess() throws SQLException {
>
> if(isTerminated()){
> if(personnelData.getEndDate() == null){
> employeeform.recordError("End date is required");
> return;
> }
> }
> ...
> }
On success is fired after the validation succeeded, so the properties are
set.
>
> //And this code doesn't because the property personnelData.getEndDate
> () appears to not have been set yet!
>
> void onValidateFromEndDate(){
> if(isTerminated()){
> if(personnelData.getEndDate() == null){
> employeeform.recordError("End date is required");
> }
> }
> }
In the field validators, the corresponding properties are not set yet. You
can get the value via a parameter:
void onValidateFromEndDate(String theDate) { ... }
If you don't use a String parameter, the type will be coerced to the class
you specified. I'm not sure which class works best for your endDate, maybe
void onValidateFromEndDate(Date theDate) { ... }
HTH, Dirk
BGS Beratungsgesellschaft
Software Systemplanung AG Niederlassung Köln/Bonn
Grantham-Allee 2-8
53757 Sankt Augustin
Fon: +49 (0) 2241 / 166-500
Fax: +49 (0) 2241 / 166-680
www.bgs-ag.de Geschäftssitz Mainz
Registergericht
Amtsgericht Mainz
HRB 62 50
Aufsichtsratsvorsitzender
Klaus Hellwig
Vorstand
Hermann Kiefer
Nils Manegold
Thomas Reitz
Re: Validation question - at which point are property values set
before post
Posted by Peter Stavrinides <P....@albourne.com>.
Thanks for the explanations, much appreciated to all.
Peter
----- Original Message -----
From: "cordenier christophe" <ch...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Wednesday, 7 October, 2009 15:07:52 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: Validation question - at which point are property values set before post
Hi
The solutions suggested by Dirk and Urlich sounds good to me.
Actually, in the submission process the target variable set with 'value'
attribute is modified only if validation succeeds. This is why your code
doesn't work.
Christophe.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Validation question - at which point are property values set
before post
Posted by cordenier christophe <ch...@gmail.com>.
Hi
The solutions suggested by Dirk and Urlich sounds good to me.
Actually, in the submission process the target variable set with 'value'
attribute is modified only if validation succeeds. This is why your code
doesn't work.
Christophe.
Re: Validation question - at which point are property values set
before post
Posted by Peter Stavrinides <P....@albourne.com>.
Anybody?
----- Original Message -----
From: "Peter Stavrinides" <P....@albourne.com>
To: "Tapestry Mailing List" <us...@tapestry.apache.org>
Sent: Tuesday, 6 October, 2009 10:07:53 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Validation question - at which point are property values set before post
Hi everyone,
I came across what seems a strange scenario to me, using Tapestry 5 validation. I am looking for a little understanding more than anything else with regards to 'the point at which properties values are set, before a form posts'... please examine this code snippet:
//This code works
public void onSuccess() throws SQLException {
if(isTerminated()){
if(personnelData.getEndDate() == null){
employeeform.recordError("End date is required");
return;
}
}
...
}
//And this code doesn't because the property personnelData.getEndDate() appears to not have been set yet!
void onValidateFromEndDate(){
if(isTerminated()){
if(personnelData.getEndDate() == null){
employeeform.recordError("End date is required");
}
}
}
personnelData.getEndDate() evaluates to a date in the onSuccess() method, but in the onValidateFromEndDate validator it is null?? the component in question is a datepicker, so the value is set via JavaScript. I am wandering why Tapestry doesn't pick up the value change until the onSuccess() event triggers.
Thanks,
Peter
---------------------------------------------------------------------
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