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 14:54:58 GMT
> -----Original Message-----
> From: V. Cekvenich [mailto:vc@basebeans.com]
> 
> I can't help on XML, but if it does not work, you are not 
> sunk since ... 
> stating the obvious ... of course you can implement the form Beans 
> validate method in which you can write ... Java.
> 
> .V
> 
> PILGRIM, Peter, FM wrote:
> > My XML skills are brain dead. I just had a thought that my role base
> > struts validation will not work as intended.
> > 
> > I intended to customise FieldChecks with validators that checks
> > against a "role" attribute in the action form. I realise that
> > the Validator does not quite work that way.
> > 
> > Normally when you write the depends attribute you want
> > to do something like this
> > 
> > 	<field property="ageText"  depends="required,integer,range" >
> >             <arg0 key="testForm.testRecord.ageText.displayname" />
> >             <arg1 name="range" key="${var:min}" resource="false" />
> >             <arg2 name="range" key="${var:max}" resource="false" />
> >             <var>
> >                  <var-name>min</var-name>
> >                  <var-value>18</var-value>
> >             </var>
> >             <var>
> >                  <var-name>max</var-name>
> >                  <var-value>125</var-value>
> >             </var>		
> > 	</field>
> > 
> > Execute the "required" validator first, then the "integer" 
> and "range"
> > ones.
> > 
> > Now with role base validation. Say I have validator that checks that
> > role was in the administration category.
> > 
> > 	<field property="ageText"  
> depends="role,required,integer,range" >
> >             <arg0 key="testForm.testRecord.ageText.displayname" />
> >             <arg1 name="range" key="${var:min}" resource="false" />
> >             <arg2 name="range" key="${var:max}" resource="false" />
> >             <var>
> >                  <var-name>min</var-name>
> >                  <var-value>18</var-value>
> >             </var>
> >             <var>
> >                  <var-name>max</var-name>
> >                  <var-value>125</var-value>
> >             </var>		
> > 
> >             <var>
> >                  <var-name>roleProperty</var-name>
> >                  <var-value>role</var-value>   <!-- name of 
> action form
> > property -->
> >             </var>            
> > 		<var>
> >                  <var-name>roleGroup</var-name>
> >                  <var-value>admin</var-value>  <!-- comma 
> delimited field
> > -->
> >             </var>
> > 
> > 	</field>
> > 
> > This validator rule say that the action form has a property called
> > "role" and the group it should check for is "admin".
> > 
> > If the action form has the role "admin" then the validation should
> > continue, if the action form does not have the role "admin"
> > then further validation should terminate. It should skip the
> > remaining validations "required", "integer" and "range"
> > 
> > Of course I dont think the Validator works this way?
> > Is it possible to skip validations? If not, then I am sunk.
> > 

--////--

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 example given in the Struts User Guide in the section 
"Conditionally required fields" is a bit too complicated.
I really do not need indexed properties so this is why it is 
confusing me. 
(http://jakarta.apache.org/struts/userGuide/printer/dev_validator.html)

What it describes though is validation on a conditional field.

It seems that customising my own copy of the "requiredif" rule
might be the path. I would like to do the following with the
role

(1)	role is member of ("admin", "management" )
	straight comparision with comma delimited list.

(2)   role matches a regular expression

	role =~ /admin|management/i


--
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