Peter L. Berghold wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi folks,
>
> I'm fairly new to all this and I'm having trouble getting validation to
> work as I thought it should. From what I've read in several books now I
> should be able to do server side validation, but in my very simple test
> case it doesn't seem to be doing anything.
>
> Here is a form bean definition I'm going to use as an example in this
> discussion:
>
> <form-bean name="sendEmailForm"
> type="org.bcdc.struts.form.SendEmailForm" />
What's the base class of SendEmailForm? It needs to be a sub-class of
ValidatorForm for automatic validation to work.
> and the associated action definition:
>
> <action
> attribute="sendEmailForm"
> input=".public.email.send"
> name="sendEmailForm"
> path="/actions/public/system/sendEmail"
> scope="request"
> validate="yes"
> type="org.bcdc.struts.action.SendEmailAction">
> <forward name="class_detail" path="/actions/public/class/detail.do" />
> <forward name="failure" path="/actions/public/sendEmail.do" />
That might need to be validate="true" rather than "yes". Otherwise, it
looks OK.
> The validation configuration:
>
> <form name="sendEmailForm">
> <field property="from_rq" depends="require,email">
> <arg0 key="sendEmailForm.from_rq.diaplay_name"/>
> </field>
> <field property="subject_rq" depends="require">
> <arg0 key="sendEmailForm.subject_rq.display_name"/>
>
> </field>
> <field property="body_rq" depends="require">
> <arg0 key="sendEmailForm.body_rq.display_name"/>
> </field>
> </form>
There is no validation rule named 'require', it should be 'required'.
I'd expect that to generate an error message if validation was actually
executing correctly.
> and here's where the Action is invoking the validation:
>
> ActionErrors ae = sendEmailForm.validate(mapping, request);
> if ( ae != null ){
> System.err.println("\t\tErrors detected, returning to the form");
> this.addErrors(request, ae);
> return mapping.findForward("failure");
>
> }
You shouldn't need this since you have validate="true" in your action
mapping. Struts will validate your form bean for you, and will not even
call your action's execute() method if validation fails. If you want to
call validation manually, set validate="false" in your mapping.
> and here is the validate() method within the form bean:
>
> public ActionErrors validate(ActionMapping mapping,
> HttpServletRequest request) {
> ActionErrors ae = super.validate(mapping, request);
> return ae;
> }
That's redundant, you don't need to override validate() if you're just
calling the parent implementation.
> Now, I invoke the sendEmail form from a browser and I'm watching the
> Tomcat logs as this is running and according to the trace validate is
> returning a null.
According to what trace? Do you mean you're not seeing the 'Errors
detected' output from your action? If so, are you sure that's not
because validation has failed and the action was never called?
> What am I missing here?
>
> This is my first attempt at using validation and none of the text I'm
> reading on this topic are very clear...
Getting all the pieces lined up can be a bit tricky the first time
through :-( If the comments above don't get you there, post your form
bean code and JSP so we have the complete picture.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)