Hi there!                                  [Windows NT, VAJ 3.5.3 WTE]


I'm trying to use the approach from the "struts-example" application to edit 
and save a form. The user is directed to "editInfo.do" which populates the 
form and forwards to "editinfo.jsp" which, on submit (starting a new 
request?), invokes the "saveInfo.do". But when I enter the perform method of 
the Action object associated with the "saveInfo" mapping a new form has been 
created and I can no longer access the values from the editInfo form. I can 
see that it hasn't merely been cleared (ActionForm.reset(...)) because I 
dump it to stdout.

I brutally 'clipboarded' the code from the struts-example app (see bottom of 
message) so I'm having a really really hard time trying to understand why it 
wont work! If you could offer any advice I would be extremely grateful.

brgds,
S. Bro



[struts-config.xml]

        <!-- Edit info -->
        <action
                path="/editInfo"
                type="myinfo.EditInfoAction"
                name="infoForm"
                scope="request"
                validate="false">

                <forward name="success" path="/editinfo.jsp" />
        </action>


        <!-- Save info -->
        <action
                path="/saveInfo"
                type="myinfo.SaveInfoAction"
                name="infoForm"
                scope="request"
                input="/editinfo.jsp"
                validate="true">

                <forward name="success" path="/editInfo.do"/>
        </action>
[/struts-config.xml]


[EditInfoAction.perform()]

public ActionForward perform(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

    // Extract attributes we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources();
    HttpSession session = request.getSession();

    // retreive the form or create a new one if it isn't there >>

    if (form == null) {
        if (servlet.getDebug() >= 1)
            servlet.log(" Creating new EditInfoForm bean under key " + 
mapping.getAttribute());
        form = new EditInfoForm();
        if ("request".equals(mapping.getScope()))
            request.setAttribute(mapping.getAttribute(), form);
        else
            session.setAttribute(mapping.getAttribute(), form);
    }

    // FORM IS POPULATED HERE

    System.out.println(form);

    // Forward control to the specified success URI
    return (mapping.findForward("success"));
}
[/EditInfoAction.perform()]

[SaveInfoAction.perform()]

public ActionForward perform(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

    // Extract attributes we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources();

    EditInfoForm infoForm = (EditInfoForm)form;    // <-- NEWLY CREATED  
FORM :(

    // TODO:    Update personal info >>
        System.out.println("SaveInfoAction.perform(): Updating info:");
        System.out.println("\t" + infoForm);



    // Forward control to the specified success URI
    return (mapping.findForward("success"));
}
[/SaveInfoAction.perform()]

Ofcourse there's alot more to the jsp file than shown here but for clarity's 
sake:

[editinfo.jsp]
<html:form action="/saveInfo">
<!-- [properties deleted] -->
<html:submit><bean:message key="editinfo.button.update"/></html:submit>
</html:form>
[/editinfo.jsp]



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Reply via email to