struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "PILGRIM, Peter, FM" <Peter.PILG...@rbos.com>
Subject RE: Role Based Struts Validation
Date Wed, 29 Jan 2003 17:25:12 GMT
> -----Original Message-----
> From: Evan Schnell [mailto:eschnell@nvisia.com]
> 
> PILGRIM, Peter, FM wrote:
> >    
--////--
> >
> >Actually I think that my understanding of the validator is flawed.
> >By default the validator will not check a field unless you
> >specify the "required". The way that "requiredif" is 
> >implemented might be clue to what I need to do. 
> >
----/////---
> 
> The "required" and "requiredIf" rules have no special short-circuit 
> behavior or impact on other rules.  It seems that all required fields 
> must be specified before any other rules are executed, but I 
> have never 
> seen this behavior formally documented anywhere.  This 
> behavior is (or 
> has been) specific to Struts and does not occur when one uses the 
> commons-validator from a non-struts application.   The point 
> is that the 
> specification of a field as  not required does not inhibit 
> execution of 
> other rules on that field.

I have been looking at the source code to `FieldChecks' I cant
see anything that describes this short cut either.

Neither

    public static boolean validateRequired(Object bean,
                                           ValidatorAction va, Field field,
                                           ActionErrors errors,
                                           HttpServletRequest request) {

or

    public static boolean validateRequiredIf(Object bean,
                                             ValidatorAction va, Field
field,
                                             ActionErrors errors,
 
org.apache.commons.validator.Validator validator,
                                             HttpServletRequest request) {

In fact my client has made a major decision, to do a lot of validation
using JavaScript using a massive library with minimum server-side
validation if they can help it.

I have been looking hard at the Struts Validator for a couple of days.
At first the XML config looked pretty cool for fast configuration. 
But it is pretty inflexible when you want to extend the validation
to conditional validation. No short circuiting. 
Default JavaScript also has its limitations.

I rendered my ActionMessages like this

errors.required=<font color='#0000CC' >{0}</font> is required.
errors.minlength=<font color='#0000CC' >{0}</font> cannot be less than <font
color='#0000CC' >{1}</font> characters.
errors.maxlength=<font color='#0000CC' >{0}</font> cannot be greater than
<font color='#0000CC' >{1}</font> characters.

The JavaScript pop-up renders the HTML code embedded.

<font color='#0000CC' >First Name</font> is required.

Who ever pays the bill decides in the end. Ah well!

> The required rule really only has application when the field 
> really is 
> _required_.  It is still possible to validate the content of 
> an optional 
> field.  For example:
> 
>            <field property="email" depends="email">
>                <arg0 key="myForm.email"/>
>            </field>
> 
> This declaration guarantees that if the user enters a value for the 
> email field it must be a valid email address.  If the user enters 
> nothing, because the field is not required no error will be 
> generated.  

--
Peter Pilgrim,
Struts/J2EE Consultant, RBoS FM, Risk IT
Tel: +44 (0)207-375-4923


********************************************************************
      Visit our Internet site at http://www.rbsmarkets.com

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
The Royal Bank of Scotland plc is registered in Scotland No 90312
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
             Regulated by the Financial Services Authority
********************************************************************

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


Mime
View raw message