You need to use the VisitorFieldValidator annotation for objects referenced
from the action. See
http://struts.apache.org/2.0.11.2/docs/visitorfieldvalidator-annotation.html
. The form doesn't look right nor does your annotation; why do you have
asterisks in the field name and why is type<[EMAIL PROTECTED] in
the annotation? That should be type=RequiredStringValidator. Maybe it got
screwed up posting to the list.

Regards,
Randy Burgess
Sr. Software Architect
D5 Systems, LLC


> From: "dug ." <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <user@struts.apache.org>
> Date: Fri, 15 Aug 2008 14:16:36 +1000
> To: <user@struts.apache.org>
> Subject: Validation referencing problem, using annotations
> 
> Hi guys
> I'm close to finishing my 1st project with struts2, which I'm quite excited
> about. I've gotten around to validation (!).
> 
> I'm having some issues getting validation to work on one of my actions. I
> can't reference the variables from the web page in order to validate them.
> I've named the variables in such a fashion that they go straight into the
> bean (go struts!).
> 
> How do I properly reference them to validate them?
> 
> 
> *my form:(*fragment)
> <s:form action="ApplyForRole" enctype="multipart/form-data" method="post">
> 
>     <h3>your contact details</h3>
>     <s:hidden name="role_id" value="%{role.role_id}" />
>     <s:textfield required="true" labelposition="top" size="25" name="*
> applicant.name"* label="name" /><br />
> ......
> </s:form>
> 
> *my action:*
> ...
> @Validations(
> requiredStrings =
> [EMAIL PROTECTED](type<[EMAIL PROTECTED](type>=
> ValidatorType.SIMPLE, fieldName = "
> *applicant.name*", message = "You must enter a value for name.")}
> )
> public class SaveApplication extends ActionSupport  {
> ...
>     //add applicant bean to this action
>     public void setApplicant(Applicant a) {
>         applicant = a;
>     }
> 
>     public Applicant getApplicant () {
>         return applicant;
>     }
> 
> }
> 
> *and the applicant bean:*
> public class Applicant {
> .....
>     private String *name*;
> .....
> 
>     public String getName() {
>         return name;
>     }
> 
>     public void setName (String s) {
>         name = s;
>     }
> ....
> }
> 
> Please point me in the right direction. Any suggested reading would
> definitely be appreciated.
> 
> Thanks
> 
> doug



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to