0

I have following code in my tiles.xml file.

I have a Struts2 Action which gets data from database and populate in sidebar.jsp in show definition I again hit another method of same action for another work and this time I populate list view definition but my previous data of siderbar.jsp does not retain its value.

I am stuck on this for a week please help me out.

   <definition name="baseLayout" template="/jsp/baseLayout.jsp">
      <put-attribute name="header" value="/jsp/header.jsp"/>
      <put-attribute name="menu"   value="/jsp/menu.jsp"/>
      <put-attribute name="body"   value="/jsp/body.jsp"/>
      <put-attribute name="sidebar"   value="/jsp/sidebar.jsp"/>    
      <put-attribute name="footer"   value="/jsp/footer.jsp"/>
   </definition>

   <definition name="show" extends="baseLayout">
      <put-attribute name="body"   value="/jsp/body.jsp"/>
   </definition>

   <definition name="listview" extends="baseLayout">
      <put-attribute name="body"   value="/jsp/listview.jsp"/>
   </definition>
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
ammad
  • 61
  • 4

1 Answers1

0

As per my understanding, sidebar.jsp is the JSP that holds the data for the sidebar. Check for the value of object which is used to populate the JSP.

 I again hit another method of same action for another work and this time
 I populate list view definition but my previous data of siderbar.jsp does not
 retain its value.

When you hit another action all the variables of the action are initialized again which might be the reason why your sidebar.jsp cannot retain the previous data.

One simple solution would be to store the data related to sidebar.jsp in session

Hope this helps :)

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Code2Interface
  • 495
  • 2
  • 7
  • I think its not a better solution to save it in a session. Is any other way to change the attribute value of a definition in tiles pragmatically. – ammad Mar 28 '13 at 10:22
  • Using tiles 3 you can extract values from the tiles definition request using wild cards and pass them into the view as a parameter (used in an expression). From there you can conditionally handle your menus. See: http://stackoverflow.com/questions/16116142/how-to-integrate-struts-conventions-with-tiles-such-that-the-benefit-of-conventi/16116396#16116396 This example shows a tiles definition which uses regex but does not show how to handle the menus with it. – Quaternion Apr 27 '13 at 04:48