Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2: Action objects not passed to JSP

 
Jonathan Su
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jonathan Su
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic