I've been working on this one, too, but on a slightly different tack.
I'm creating a page to do administrative work (add/edit/delete users)
and I want to go back to the edit page if the user forgets to fill
in some required field.  Not necessary sharing a form between 
different JSPs, but shared with the same one.

I have an Admin.jsp that contains all the administrative options,
and an EditUser page that allows the administrator to add a new user.
Once the user has been added, control should go back to the Admin.jsp.
If there was a problem, control should stay on the EditUser.jsp until
the problem is resolved.  All of the information already entered
should be in the EditUser.jsp so the user doesn't have to retype it.

In my struts-config.xml, I have these:

    <form-beans>
    <form-bean name="userForm" type="com.company.UserForm"/>
    </form-beans>

    <action-mappings>
        <action    path="/edituser"
                   type="com.company.EditUserAction"
                   name="userForm"
                  scope="session"
                  input="/EditUser.jsp">
            <forward name="success" path="/Admin.jsp"/>
        </action>
    </action-mappings>

In my EditUser.jsp, I have the following code:

    <font color="red"><html:errors/></font>
    <html:form name="userForm" action="edituser.do" 
          type="com.comapny.UserForm" scope="session">
    <html:hidden property="id"/>
    Login: <html:text property="login"/><br>
    Name: <html:text property="name"/><br>
    Password: <html:password property="password"/><br>
    Confirm: <html:password property="password2"/><br>
    <html:submit/><html:cancel/>
    </html:form>

Things to note:

1) The /edituser action uses the form bean "userForm" at the session 
   scope as defined in the action-mapping.
2) The EditUser.jsp has an <html:form> tag with a name attribute with a
   value "userForm" and a scope of "session"; this is the same as the 
   parameters defined in the action-mapping (very important!)

Based on that assumption, I guess you'd do something like the following
to share a form across pages:

struts-config.xml:
    <form-beans>
    <form-bean name="userForm" type="com.company.UserForm"/>
    </form-beans>

    <action-mappings>
        <action    path="/part1"
                   type="com.company.Part1Action"
                   name="userForm"
                  scope="session"
                  input="/part1.jsp">
            <forward name="success" path="/part2.jsp"/>
        </action>

        <action    path="/part2"
                   type="com.company.Part2Action"
                   name="userForm"
                  scope="session"
                  input="/part2.jsp">
            <forward name="success" path="/done.jsp"/>
        </action>
    </action-mappings>

part1.jsp
    <font color="red"><html:errors/></font>
    <html:form name="userForm" action="part1.do" 
          type="com.company.UserForm" scope="session">
    . . . . .
    </html:form>

part2.jsp
    <font color="red"><html:errors/></font>
    <html:form name="userForm" action="part2.do" 
          type="com.company.UserForm" scope="session">
    . . . . .

I think that the session scope might be assumed (by default), but
better safe than sorry! :-)


----- Original Message ----- 
From: "O'Neill, John H" <JohnH.O'[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 27, 2001 12:02 PM
Subject: ActionForm and reset method question


> Hi,
> 
> I'm having trouble accumulating data across mutiple JSP pages using a 
> single ActionForm object.  Having read the previous postings on this
> subject it seems that the ActionForm object has session scope and that
> its reset methods default implementation does nothing to the ActionForms
> data. Could someone confirm if this is correct or let me know if I'm
> misunderstanding things?
> 
> If you could point me to an example (if there is one) of how you would
> go about implementing the above also it would be much appreciated!
> 

Reply via email to