<struts-newbie>

This might be heretical, but why can't you just call the form bean's validate 
method from your action servlet.  It still does the "business logic" of 
validating the form and you'd still be able to validate your user.


ActionErrors errors = new ActionErrors();
MyForm myForm = (MyForm) form;
// validat user ...
// explicitly call the form's validate method
errors = myForm.validate();
// check to see if it returned errors
if ( !errors.empty() ) {
        // save the specified error messages into the request
        // so that you can use the <struts:errors> tag
        saveErrors(request, errors);
        // return to the original form
        return ( new ActionForward( mapping.getInput() ) );
        // or return ( mapping.findForward("failure") ) if you like
}


No?
</struts-newbie>

On Wednesday 21 November 2001 14:51, you wrote:

> > I have a form which I want to prepopulate with some general data (eg. a
> list or provinces) from a database along with some user specific data again
> from a database (eg. user name).  The form is also secure so I want the
> user to be "logged in" to access it.
>
> So I have set up:
>
> Page.jsp - the view containing the form
> PageForm.java - extends ActionForm
> PageAction.java - extends Action and set in mapping as pageAction.do
>
> In PageAction I check for a session attribute which tells me whether or not
> the user is logged in.  If the user is not logged in I forward them to a
> login sequence.
>
> The problem is when I call pageAction.do the PageAction is never called. 
> The reset() and validate() methods on PageForm are called but then Page.jsp
> is displayed without ever having called PageAction's perform() and
> therefore never doing security authentication.
>
> So no security validation occurs.  I have no opportunity to prepopulate the
> form.  I did cheat in a way by having reset() set the general data but I
> still need a way to prepulate the personal data that I want pre-filled on
> the form *once* when it's first displayed and then allow the user to change
> from then on.  So if they change their name on the form, for example, but
> make an error on the form then when the form is redisplayed it doesn't
> reset the name back to what's in the database but instead shows the changed
> name.
>
> In my mapping I have the input attribute set to Page.jsp.  Perhaps I'm
> misusing this attribute.
>
> Thanks for any and all help.
>
> Derek


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

Reply via email to