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 2: Action objects not passed to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2: Action objects not passed to JSP" Watch "Struts 2: Action objects not passed to JSP" New topic
Author

Struts 2: Action objects not passed to JSP

Jonathan Su
Greenhorn

Joined: Aug 23, 2007
Posts: 4
I am building a web application using Struts 2 when I come across a seem-to-be weird problem.

Well defined object attributes in action class sometimes cannot not be passed to JSP. But sometimes it works just fine and everything shows in JSP corretly.

It happens very radomly and I really cannot tell the pattern.

I have made sure that before the action return 'SUCCESS' the objects are still there, whereas on the jsp side, they turn into nulls.

The following is section of my struts.xml:

<action name="launch" class="org.delta.qa.web.action.MemberInquiryAction" >
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="inputValidator"/>
<result name="success">jsp/MemberInquiry.jsp</result>
<result name="error">jsp/error.jsp</result>
<result name="new_member" type="chain">preprocess</result>
</action>

Do I need to define the object type in struts.xml or somewhere else?

Any help would greatly appreciated!!

Jonathan
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid we don't have enough information to be of much help. Could you please post relevant portions of your MemberInquiryAction class and JSP?


Merrill
Consultant, Sima Solutions
Jonathan Su
Greenhorn

Joined: Aug 23, 2007
Posts: 4
Here is my scenario in more detail:

Class AbcActionBean extends ActionSupport {
protected MemberEntity member; //MemberEntity is defined in Entity package.
with public getter and setter.
}

Class MemberInquiryAction extends AbcBean {
execute() {
.......
member is populated from DB.
.......
// at this point member is still populated
return SUCCESS;
}
}

In JSP side, I am trying to display member info like this
<input type="text" name="member.firstName" value"${member.firstName}"/>
or directly, <td>${member.age}</td>

For debug purpose I display ${member} on the screen just to see if the object is there.

Very randomly when the jsp is display the member object become null and obviously no attribute of it would show. If I repeat the same action it would show again.

Please help.

Jonathan
Jonathan Su
Greenhorn

Joined: Aug 23, 2007
Posts: 4
One thing I notice is that only the types I defined in the application have this problem. String, ArrayList (although has custom-defined components), int, float etc, can be passed without any issue.
 
GeeCON Prague 2014
 
subject: Struts 2: Action objects not passed to JSP