I guess I'm going to answer my own question here, though the fact that
my question seems extremely ungoogleable(!) suggests I'm going about
this ass-backwards...
What I did was check hasFieldErrors() at the end of validation method
of the form submission - if true, then I just rebuild my objects for
use in the form. Then when Struts2 uses the dispatcher to send me back
to the form JSP, the objects the form needs are in value stack.
I'm guessing the objects don't persist into the action after form
submission because Struts is just blindly calling the setters and
getters for the form fields, and doesn't give a crap about stuff in
the value stack - it's not going to read them all and call the setters
and getters for those as well.
If anyone else is doing something similar, it would be nice to know I
haven't gone totally insane.
Andy.
On 13 Dec 2008, at 16:26, Andy Sykes wrote:
Hi all,
I've got an action called "edit" that prepares some objects for use
in a form (Lists for select tags, etc), then dispatches to the JSP
form. It's dependent on having a parameter passed to it via a GET
url (e.g. edit.action?id=4) to build these objects.
This form submits to another action, "doedit", and there's some
programmatic validation on this action. If I use the Dispatcher
result type on the input result, Struts dispatches to the JSP form
again, but since it never calls the first "edit" action, the form
controls don't get populated. If I do redirect-action on the input
result, I get back to the form, but Struts seems to have "forgotten"
the FieldErrors object, so I get no validation messages.
How do you deal with validation when you're using actions to prepare
forms like this? Am I approaching the rich forms generation the
wrong way, and there's a better way?
Thanks for any advice, since I'm banging my head against the wall on
this - I must be missing something obvious.
Cheers,
Andy.
--
Andy Sykes
IT Support Officer
UCL Museums & Collections /
Media Resources
a.sy...@ucl.ac.uk
Room 225, 2nd Floor
Wilkins Building
(Mon/Tues/Wed AM)
Tel: 0207 679 67667 | x37667
Charles Bell House
43-45 Foley Street
(Wed PM/Thurs/Fri)
Tel: 0207 679 99164 | x09164
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org