Ask Experts Questions for FREE Help !
Ask
    crazy287's Avatar
    crazy287 Posts: 3, Reputation: 1
    New Member
     
    #1

    Sep 23, 2013, 06:35 AM
    Struts2- Persistence of objects values between different actions in the same Action c
    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 every time? 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>

Check out some similar questions!

Displaying the ACORD JAXB Java elements in JSP in Struts2 [ 0 Answers ]

Scenario: I am trying to unmarshall the Acord XML(Insurance standard XML) to Java-Acordform and then trying to map the Acordform object to a one more formbean-Policformbean in order to display the values in the JSP where user can edit the values.Again I have to marshall the Java object values to...

Report creation in struts2 [ 0 Answers ]

Hi to all, I am new to the struts2. But now I am trying to generate report in struts2. But I already create .jasper and .jrxml files using iReport3.7.3 with userId parameter. I don't know the next step. Can anyone share your knowledge with me. Thanks.

How do I alternatively plead an action for quiet title, an action based upon adverse [ 3 Answers ]

How do I plead a cause of action for quiet title based on a boundary dispute and then plead alternatively for title based upon adverse possession and then plead alternatively for prescriptive easement?

Falling objects? [ 2 Answers ]

Here is the ?s hope u can help me guys... A juggler throws a ball up into the air. The ball remains in the air for a time(t) before it runs back into the jugglers hand. 1. With what speed did the juggler throw the ball into the air? (Hint: What is the total displacement of the ball...

Falling objects [ 1 Answers ]

A juggler throws a ball straight up into the air. The ball remains in the air for a time before it lands back in the jugglers hand. With what speed did the juggler throw the ball into the air?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.