The way I solved this problem by putting my dropdown collections directly
into the session. And I make sure I remove them in a timely manner. If the
user aborts (leaves) after viewing the first page then there is some waste
but it is quick and easy to implement. I do my error handling in the struts
config so no messy try/catch etc.
Action to display the form:
/*
* Called if the specified request parameter passed to invoke this
* action has the value "display". I am actually using Dispatch
* Action here and the name of this method would be display as in
* display the page and the two actions described are really one.
* But for simplicity sake I make them two forms for this demo.
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
log.info("In display()");
//Get all necessary persistent data to populate dropdowns etc. ...
//Put in Session in case validation fails on the way back in
HttpSession session = request.getSession();
//Get a list of all the possible Branches a User can be assigned
List branches = UserManager.getAllUserBranchTypes();
session.setAttribute(Const.BRANCH_TYPES, branches);
//Get a list of all possible Roles a User can be assigned
List roles = UserManager.getAllUserRoleTypes();
session.setAttribute(Const.ROLE_TYPES, roles);
return (mapping.findForward("displayForm"));
}
Action hit after submit:
/*
* Called if no request parameters passed in when invoking this action.
* This is really the unspecified method in my 1 action so that a post
* comes here. I renamed it as a second action for this example.
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
log.info("In unspecified()");
DynaActionForm loginForm = (DynaActionForm)form;
//Create User object in memory to be persisted
//...
//Populate it with form properties
log.info("Persisting new User");
UserManager.persistNewUser(newUser);
//All went well so clean up Session which had dropdown info
request.getSession().removeAttribute(Const.BRANCH_TYPES);
request.getSession().removeAttribute(Const.ROLE_TYPES);
return (mapping.findForward("showConfirm"));
}
-----Original Message-----
From: Doug Padian [mailto:[EMAIL PROTECTED]
Sent: Monday, June 09, 2003 7:44 PM
To: Struts Users Mailing List
Subject: On failed validation, trouble with form
I have a Form that maintains a couple collections that are populated by the
Action class. If this form fails validation, the struts servlet sends the
request back to the input page, but then the collections are empty.
In "Struts In Action", page 310, Ted Husted talks about routing the failed
request through another Action method that repopulates those collections. I
tried writing a method like that in my Action class, named "invalidUser"
which regenerates the collections that I need and puts them back into the
form. My entry in the struts-config looks like this:
<action path="/user_admin_editor/submit_user"
type="com.ignitemedia.sportseditor.user.struts.UserAction"
name="userForm"
scope="request"
parameter="method"
validate="true"
input="/user_admin_editor/edit_user.do?method=invalidUser"
>
<forward name="success"
path="/pages/user_admin_editor/confirm.jsp"/>
</action>
If the validation fails, the input call goes to edit_user.do, with the
method name invalidUser.
For whatever reason, this doesn't work. At first I was getting errors
saying it couldn't find the invalidUser method. Then I changed the
"inputForward" attribute of the <controller> tag to "true". I don't get the
errors now, but just a blank page.
I'm a little clueless. Any ideas out there?
-Doug Padian
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]