Struts update form validation

D

Dan

Much has been posted regarding the pre-population of a form in a
Struts MVC application (such as pre-populating a listbox or entry
fields on a form). Generally speaking, the solution is to create
"pre" actions (such as EditAccountAction) that perform db or other
setup activity that forward to a jsp rather than invoking a jsp
directly. For validation, it has been suggested that the "input"
property of the action that handles the submission (such as a
UpdateAccountAction) simply point to the EditAccountAction rather than
the jsp. This has the benefit of calling the setup code once again
upon validation errors.

However, if you want to display the SUBMITTED data upon a failed
validation (such as missing field values) rather than the values
retrieved from the database once again there must be someway to have
the EditAccountAction be smart enough to recognize that we are in a
validation situation rather than a first time access situation. In my
application, this would be necessary in order to prevent the account
fields from being over written each time with fresh data (whereby
wiping out what could be other valid entries by the user).

I should note that it is still necessary to have the input property to
the pre-action since there are drop down boxes that still need to be
built in this step.

Any suggestions or best practices?
 
W

Wendy S

Dan said:
However, if you want to display the SUBMITTED data upon a failed
validation (such as missing field values) rather than the values
retrieved from the database once again there must be someway to have
the EditAccountAction be smart enough to recognize that we are in a
validation situation rather than a first time access situation.

First, do you *really* need to hit the database on every form display? Are
the contents of these drop down boxes that volatile? Personally, I populate
a bunch of Maps and stick them in Application scope. But in my app, the
contents of the "Type" drop down box change very rarely, and bouncing the
webapp on maintenance weekend to load the new values is acceptable. There's
a middle ground, and that's the session. Can you load the info for the
drop-downs once per session instead of every time the form is displayed?

If not, just override the execute method in EditAccountAction and look for
something that tells you whether the form has been submitted. Could be that
the request was POSTed to you, or put a hidden field on the form and look
for it. Then decide whether to do the pre-population or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top