• 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

JSP Form data lost while back to same Action (struts 2)

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have to action classes, say Test1 and Test 2 and two jsp pages,say jsp1 and jsp2, while jsp1 is related to Test1 and jsp2 is related to Test2. And the page flow is like , first the user will enter some data in jsp1 and click on next to go to the next page(jsp2) and also we have to display some of the fields entered injsp1. So I have extended Test2 to Test1, so that Test2 will contains all the commons fields and respective setters and getters.

As expected, on click on the next button, the data the jsp1 data is getting dispalyed in jsp2.Now while I'm trying to post the data from jsp2 and as a result users are reditected to the same page , jsp2, all the fields(inherited from Test1) are vanising.

Can some one help me out?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 2 actions are instantiated per-request.
 
Abhi Roy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David, so what do you suggest to set the form fields in request as DTO to get the affect? Or is there any mechanism?

Thanks again for you input.

/Abhi
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep the list in session or application context, regenerate the list, assume your persistence solution has reasonable caching, etc.
 
Abhi Roy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear David,

Thanks for the solution, but in that case I beleive session will be overloaded. I want to keep this one as the last defence.I have just tried with a small PoC,
here is the code

My JSP -
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>

<body>
<s:form id="Login" name="Login" action="myAction">
<s:textfield value="%{userid}" name="%{userid}">
</s:textfield>
<s:submit>Login</s:submit>
</s:form>
</body>
</html>

My Action Class

public class MyTestAction extends ActionSupport implements ServletRequestAware {

private static final long serialVersionUID = -3594301868048109081L;
private String userid;
private HttpServletRequest request;


public String execute() throws Exception {
System.out.println("Step 3");
setUserid(userid);
if(this.userid!="sa")
return SUCCESS;
else
return INPUT;
}

public String getUserid() {
System.out.println("Step 1 " + userid);
return userid;
}

public void setUserid(String userid) {
System.out.println("Step 2 " + userid);
this.userid = userid;
}

public void setServletRequest(HttpServletRequest request) {
System.out.println("Step 4");
this.request = request;
}
}


and my Sturts.xml

<struts>
<include file="struts-default.xml" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="ajaxdemo" extends="struts-default">
<action name="myAction" class="ajaxdemo.action.MyTestAction">
<result name="input">/mydetail.jsp</result>
<result>/mydetail.jsp</result>
</action>
</package>
</struts>

A very simple form with a textbox and user can enter his name. But every time, both the setter and getter of the userid are printing null.

Sorry to disturb you again.
Thanks
 
Abhi Roy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry ,
I'm calling that page from another index page...which is as follow


and one more correction, in my previous jsp, mydetail.jsp, that should look like


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was there an additional question?

You're not providing enough information to help. If you don't submit a userId or have some other means of getting it (hidden form field, etc.) then yes, it will print null--it's not initialized.
 
Abhi Roy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok...let me try in that way....thanks for your response....
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhi Roy wrote:ok...let me try in that way....thanks for your response....


use getUserid instead of this,userid and remove setUserid. You are setting the userid to null here. On submit you should get the value by using getUserid
reply
    Bookmark Topic Watch Topic
  • New Topic