• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts2- Persistence of objects values between different actions in the same Action class

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scenario: On click of a 'Submit' button I have unmarshalled the XML to Java and then displaying the Java objects(created a formbean and mapped the JAXB java Objects to this formbean- PolicyForm and using this formbean to display in JSP) in the JSP.This is working fine.

Issue: I have one more button -Calculate on the same page with in the same form of Submit button. On click of the 'Calculate' button I need to get the acordform values which was unmarshalled during the click of Submit button. Here I am not able to get the acordform values instead I am getting the new object of acordform.

When I have googled I see- Struts 2 doesn't have thread-safety issues as "Action objects are instantiated for each request". Please let me know here when I am sending the request again is the Action object- acordform being instantitaed everytime? If yes, how can I avoid this ? Since I need the acordformobject values even in the next request too.

Action Class:
public class RateAction extends ActionSupport implements
ServletRequestAware,SessionAware {

/* ... */

// ACORD xml form bean
private ACORD acordform = new ACORD();

//To display the values in the JSP
private PolicyForm policyForm;

public ACORD getAcordform() {
return acordform;
}

public void setAcordform(ACORD acordform) {
this.acordform = acordform;
}

public String doSubmit() {
/*...Unmatshalling from XML to Java -acordform is done..*/
}

public String doRateSubmimt()
{
/*..trying to get the acordform values which are being set
previously in doSubmit() method...*/
}
}

Struts.xml:
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/" >

<action name="fileUploadAction"
class="com.main.common.action.RateAction" >
<interceptor-ref name="fileUpload">
<param name="allowedTypes">text/xml</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="params"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="basicStack"/>
<result name="success">First.jsp</result>
<result name="input">First.jsp</result>
</action>

<action name="submitAction" class="com.main.common.action.RateAction" method="doSubmit">
<result name="success">First.jsp</result>
</action>
<action name="rateAction" class="com.main.common.action.RateAction" method="doRateSubmit">
<result name="success">First.jsp</result>
</action>
</package>

JSP:

<s:form id="rtr" action="fileUploadAction" method="POST"
enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<s:file name="uploadFile" label="Upload Request XML" />
<s:submit value="Submit" action="submitAction" onclick="displayDetails();" />
<s:hidden name="submitSuccess" />
<s:submit value="Calculate" action="rateAction" />
</tr>
</table>
</s:form>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic