Having overcome my validation problem with help from the list (thanks Bill) I now find myself banging my head against another wall.

I now have a multi-page form backed by an ActionForm and an Action that appears to work fine (stepping from one page to the next, accepting input, validating it, storing it in an object in a session) except for the fact that the JSP pages do not retrieve the accumulating data from the object stored in the session, other than the first piece of data entered and the last. So I get a growing number of blank fields in the page.

I have built and run a multi-step unit test with Struts Test Case that works fine. The Action creates the required object, stores it in the session, and adds the data piece by piece as the unit test simulates stepping through the wizard.

This has at my wits end.

Below is the code from the Action and one of the JSP pages that fails. Note: Only the first four pages are currently processed by business logic. The rest just return success regardless.

I can't see what I am doing wrong. It seems like the object stored in the session isn't being updated properly (although the unit test disproves this), so perhaps its something I have messed up in the JSP, or don't fully understand?

Any assistance anyone can offer would be greatfully received.

Regards,
Langdon

----------------------------------

StudentRegistrationWizardAction.java

package adamh;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * User: langdons
 * Date: 18/08/2004
 * Time: 18:44:41
 * To change this template use Options | File Templates.
 */

public class StudentRegistrationWizardAction extends Action{

private static Log log = LogFactory.getLog(StudentRegistrationWizardAction.class);

public static final String STUDENT_KEY = "adamh.StudentRegistrationWizardAction.STUDENT";

    public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
            throws Exception {
        log.trace("In execute of StudentRegistrationWizardAction");



        if ((request.getSession().getAttribute(STUDENT_KEY)) == null) {
            Student newStudent = new Student();
            request.getSession().setAttribute(STUDENT_KEY, newStudent);
        }

        /* Check to see if the user cancellend the registration process */
        if (isCancelled(request)) {
            log.debug("Cancel Button was pushed!");
            request.getSession().removeAttribute(STUDENT_KEY);

            request.getSession().removeAttribute(mapping.getAttribute());

            return mapping.findForward("welcome");
        }

/* Get the form data */
StudentRegistrationWizardForm studentForm = (StudentRegistrationWizardForm) form;


        int page = studentForm.getPage();

if (page == 1) {
return processRegReferrer(mapping, studentForm, request, response);
} else if (page == 2) {
return processEmailAddress(mapping, studentForm, request, response);
} else if (page == 3) {
return processPassword(mapping, studentForm, request, response);
} else if (page == 4) {
return processNickname(mapping, studentForm, request, response);
} else if (page == 5) {
return mapping.findForward("success");
} else if (page == 6) {
return mapping.findForward("success");
} else if (page == 7) {
return mapping.findForward("success");
} else if (page == 8) {
return mapping.findForward("success");
} else if (page == 9) {
return mapping.findForward("success");
}
return processRegReferrer(mapping, studentForm, request, response);
}



public ActionForward processRegReferrer(
ActionMapping mapping,
StudentRegistrationWizardForm studentForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
log.trace("In processRegReferrer of StudentRegistrationWizardAction");
String referrerId = studentForm.getReferredById();
Student student = (Student) request.getSession().getAttribute(STUDENT_KEY);


if (student == null) {
throw new java.lang.IllegalStateException(
"Missing student in session scope");
} else {
if (referrerId != null) {
/**
* TODO: Check the databse to see if the referrer id is valid, if so then add the id to the student object, if not, then dump it
*/
student.setReferredById(referrerId);
}
request.getSession().setAttribute(STUDENT_KEY, student);
return mapping.findForward("success");
}
}



public ActionForward processEmailAddress(
ActionMapping mapping,
StudentRegistrationWizardForm studentForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
log.trace("In processEmailAddress of StudentRegistrationWizardAction");


/* Get the Student in session scope, fail if not present */
Student student = (Student) request.getSession().getAttribute(STUDENT_KEY);


if (student == null) {
throw new java.lang.IllegalStateException(
"Missing student in session scope");
} else {
String emailAddress = studentForm.getEmailAddress();
Student studentCheck = (Student) StudentService.getInstance().getStudentByEmailAddress(emailAddress);
if (studentCheck != null) {
return mapping.findForward("emailAddressExists");
} else {
student.setEmailAddress(emailAddress);
request.getSession().setAttribute(STUDENT_KEY, student);
return mapping.findForward("success");
}
}
}



public ActionForward processPassword(
ActionMapping mapping,
StudentRegistrationWizardForm studentForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
log.trace("In processPassword of StudentRegistrationWizardAction");
/* Get the Student in session scope, fail if not present */
Student student = (Student) request.getSession().getAttribute(STUDENT_KEY);
if (student == null) {
throw new java.lang.IllegalStateException(
"Missing student in session scope");
} else {
student.setPassword(studentForm.getPassword());
request.getSession().setAttribute(STUDENT_KEY, student);
return mapping.findForward("success");
}
}



public ActionForward processNickname(
ActionMapping mapping,
StudentRegistrationWizardForm studentForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
log.trace("In processNickname of StudentRegistrationWizardAction");
/* Get the Student in session scope, fail if not present */
Student student = (Student) request.getSession().getAttribute(STUDENT_KEY);
if (student == null) {
throw new java.lang.IllegalStateException(
"Missing student in session scope");
} else {
student.setNickname(studentForm.getNickname());
request.getSession().setAttribute(STUDENT_KEY, student);
return mapping.findForward("success");
}
}



public void updateSessionStudent(HttpServletRequest request, Student student) {


    }

}

-----------------------------

studentRegNickname.jsp

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>

<html>
<head>
<title>Student Registration - Choose a Nickname</title>
</head>
<body>
<h1>Student Registration - Choose a Nickname</h1>
<html:errors/>
<table>
<html:form action="studentRegNickname">
<tr>
<td>
<bean:message key="studentRegistrationWizard.referredById" />:
</td>
<td>
<bean:write name="student" property="referredById" />
</td>
</tr>
<tr>
<td>
<bean:message key="studentRegistrationWizard.emailAddress" />:
</td>
<td>
<bean:write name="student" property="emailAddress" />
</td>
</tr>
<tr>
<td>
<bean:message key="studentRegistrationWizard.password" />:
</td>
<td>
<bean:write name="student" property="password" />
</td>
</tr>
<tr>
<td>
<bean:message key="studentRegistrationWizard.nickname"/>:
</td>
<td>
<html:text property="nickname"/>
</td>
</tr>
<tr>
<td>
<html:submit/>
</td>
<td>
<html:cancel/>
</td>
</tr>


                <!-- Added hidden variable so Action execute,
                         and ActionForm validate knows which page their on -->

                <html:hidden property="page" value="4"/></html:form>

        </html:form>
        </table>
</body>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to