I can't test this right now, but if I have an ActionMapping with validate="true" and no input, won't that result in an
error when validate fails? My understanding is that if validate fails, the request processor forwards the request to
the input.
------------------------------------------------------------------------
Subject:
Re: Re-populating form after validate fails
From:
[EMAIL PROTECTED]
Date:
Wed, 4 Feb 2004 10:59:35 +1100
To:
"Struts Users Mailing List" <[EMAIL PROTECTED]>
Just set up an forward for validation failure. You can do this in your
struts-config.xml file, in fact you can have as many forwards as you
like, but for practical purposes most people prefer to have at most three
or four forwards per Action. For example, you might have a SaveAction that
forwards to the next screen in a sequence if validation succeeds, an error
page if it fails, a login page if the session becomes invalidated, and a
query action if you had a "delete" button to delete a record.
Just say you query a database to populate your form fields. Then you can
edit the form and hit Save. In the Form's validate method you fill an
ActionErrors object.
Then in the SaveAction you will have something like:
// If a message is required, save the specified key(s)
// into the request for use by the <struts:errors> tag.
if (!errors.isEmpty())
{
saveErrors(request, errors);
// Forward control to the appropriate 'failure' URI
forward = mapping.findForward("failure");
}
else
{
// Forward control to the appropriate 'success' URI if no errors
forward = mapping.findForward("success");
}
return forward;
and in your struts-config you will have something like:
<action path="/saveAction"
type="myproject.actions.SaveAction"
name="somethingForm"
validate="true">
<forward name="success" path="nextForm/>
<forward name="failure" path="somethingForm"/>
</action>
I hope you can figure out your answer from that... I can't give you a real
example from my project because of confidentiality so I have to try and
make it generic.
Cheers,
Heya Gosper
CSC Australia
212 Northbourne Ave, Braddon ACT 2612
Ph: +61 (0) 2 6246 8155 Fax: +61 (0) 2 62468100
MOB: 0401 611779
----------------------------------------------------------------------------------------
This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit
written agreement or government initiative expressly permitting the use of
e-mail for such purpose.
----------------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]