File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts 1.3: request attributes lost after submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1.3: request attributes lost after submit" Watch "Struts 1.3: request attributes lost after submit" New topic
Author

Struts 1.3: request attributes lost after submit

Fran Cricket
Greenhorn

Joined: Nov 03, 2012
Posts: 9
I have two jsp page, say form.jsp and myForm.jsp.

In the first page, form.jsp, there is a radio button group (the form name is "form").
When the user submits this form, some info are retrieved from a db and with these informations the form in myForm.jsp is built (the form name is "myForm").
The problem is that when this second form is submitted, only the errors are displayed but not the form fields created from db values.
For example, I retrieve from database labels and values for two radio buttons (property="prop").
In struts-config.xml, I have:

<form-bean name="myForm" type="org.apache.struts.validator.MyValidatorActionForm">
<form-property name="prop" type="java.lang.Integer"></form-property>
</form-bean>
...
<action path="/form" input="/jsp/home.jsp" name="form"
scope="request" type="myPackage.LoadInfo">
<forward name="Success" path="/jsp/myForm.jsp"/>
<forward name="Failure" path="/jsp/home.jsp" />
</action>

<action path="/myForm" input="/jsp/myForm.jsp" name="myForm" validate="true" scope="request" type="myPackage.MyValidatorAction">
<forward name="Success" path="/jsp/success.jsp"/>
<forward name="Failure" path="/jsp/failure.jsp"/>
</action>


In myForm.jsp:

<html:form action="/myForm">
<div><label>* <bean:message key="myForm.label"/></label>
<c:forEach var="propTypes" items="${props}">
<html:radio property="prop" value="${propTypes.value}">${propTypes.label}
</html:radio>
</c:forEach>
  <html:errors property="prop" />
</div>
<div><html:submit><bean:message key="myForm.label2"/></html:submit></div>
</html:form>


In validation.xml:

<formset>
<form name="/myForm">
<field property="prop" depends="required">
<arg key="myForm.label"/>
</field>
</form>
</formset>


After the form submit without select any radio button, the error is displayed, but not the radio buttons.

How could I maintain all the request attributes?
I tried to use scope session too, but nothing has changed:

<action path="/myForm" input="/jsp/myForm.jsp" name="myForm" validate="true" scope="session" type="myPackage.MyValidatorAction">
<forward name="Success" path="/jsp/success.jsp"/>
<forward name="Failure" path="/jsp/failure.jsp"/>
</action>


I resolved by using:

request.getSession().setAttribute("props", props);


in the Action LoadInfo called before the display of the form.

In myForm.jsp I use:

request.getSession().getAttribute("props");


Instead in the struts-config.xml, the scope remains request.

Nevertheless, this isn't a good solution, 'cause different browser tabs share the same session.

How could I resolve this issue?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts 1.3: request attributes lost after submit
 
Similar Threads
Username existence check using AJAX and Java J2EE
Verification failed on Username existence check using AJAX
Cannot retrieve definition for form bean StudentBean on action /studentList?listAction=acceptRejectU
Struts 1.3 validation: request attributes are lost after submit form
text field not populating after validate() fails.