You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2008/03/22 02:55:36 UTC

t5: validator questions...

Hi,

Looking at Tapestry.js' addValidator for 'Required':

required : function(field, message)
 {
     Tapestry.addValidator(field, true, function(value, event)
     {
         if (value == '')
             event.recordError(message);
     });
 },

and also the Required.java, it has a validation too:

public void validate(Field field, Void constraintValue, MessageFormatter
formatter, Object value)
          throws ValidationException
  {
      if (value == null || value.toString().equals("")) throw new
ValidationException(buildMessage(formatter, field));
  }

Why the same condition is being checked in two places, any reason? thanks.

A.C.
-- 
View this message in context: http://www.nabble.com/t5%3A-validator-questions...-tp16213766p16213766.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: validator questions...

Posted by Robert Zeigler <ro...@scazdl.org>.
Don't declare the field as mandatory.
Then add your custom validation to onValidateFromXXX where XXX is the  
id of your form.
Validate the id there.

Alternatively, you could contribute your own validator, which doesn't  
perform any client-side validation.

Robert

On Mar 21, 2008, at 3/219:50 PM , Angelo Chen wrote:
>
> Hi Robert,
>
> oh i see, so for every validation you have to code two, one in java  
> and
> another one in js, this does bring up another question, can
> 'clientvalidation' be set in the field level? say, I have a form,  
> all the
> fields can be validated client side except a customer id field, which
> requires using the server side validator, yes, we can add a js  
> validator
> then call the server side validator, but that requires kind of  
> effort, a
> easier approach will be, turn the clientvalidation on for the form,  
> then
> turn the clientvalidation off for the field, any idea? Thanks,
>
> A.C.
>
> Robert Zeigler wrote:
>>
>> One is for client-side validation, and the other is for server-side
>> validation?
>> Client-side validation is a nicety that makes the validation process
>> less painful for a client.
>> But you can't rely on it for any sort of "security" since all it  
>> takes
>> to bypass it is to turn of javascript.
>> Hence, you must also perform a server-side check.
>>
>> Cheers,
>>
>> Robert
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/t5%3A-validator-questions...-tp16213766p16214692.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: validator questions...

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Robert,

oh i see, so for every validation you have to code two, one in java and
another one in js, this does bring up another question, can
'clientvalidation' be set in the field level? say, I have a form, all the
fields can be validated client side except a customer id field, which
requires using the server side validator, yes, we can add a js validator
then call the server side validator, but that requires kind of effort, a
easier approach will be, turn the clientvalidation on for the form, then
turn the clientvalidation off for the field, any idea? Thanks,

A.C.

Robert Zeigler wrote:
> 
> One is for client-side validation, and the other is for server-side  
> validation?
> Client-side validation is a nicety that makes the validation process  
> less painful for a client.
> But you can't rely on it for any sort of "security" since all it takes  
> to bypass it is to turn of javascript.
> Hence, you must also perform a server-side check.
> 
> Cheers,
> 
> Robert
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-validator-questions...-tp16213766p16214692.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: validator questions...

Posted by Robert Zeigler <ro...@scazdl.org>.
One is for client-side validation, and the other is for server-side  
validation?
Client-side validation is a nicety that makes the validation process  
less painful for a client.
But you can't rely on it for any sort of "security" since all it takes  
to bypass it is to turn of javascript.
Hence, you must also perform a server-side check.

Cheers,

Robert

On Mar 21, 2008, at 3/218:55 PM , Angelo Chen wrote:
>
> Hi,
>
> Looking at Tapestry.js' addValidator for 'Required':
>
> required : function(field, message)
> {
>     Tapestry.addValidator(field, true, function(value, event)
>     {
>         if (value == '')
>             event.recordError(message);
>     });
> },
>
> and also the Required.java, it has a validation too:
>
> public void validate(Field field, Void constraintValue,  
> MessageFormatter
> formatter, Object value)
>          throws ValidationException
>  {
>      if (value == null || value.toString().equals("")) throw new
> ValidationException(buildMessage(formatter, field));
>  }
>
> Why the same condition is being checked in two places, any reason?  
> thanks.
>
> A.C.
> -- 
> View this message in context: http://www.nabble.com/t5%3A-validator-questions...-tp16213766p16213766.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