Hello...
I'm using a <tiles-definitions>...</tiles-definitions> XML file to represent
definitions of tabs that will be used in an application. The layout of our application
is similar to MS Explorer: left side is a tree and once a node is clicked, the right
side is the view of that node. I am able to remember which tab is selected between
each request for each node by the following piece of code (from a modified
tabsLayout.jsp example)
<tiles:useAttribute name="parameterName" classname="java.lang.String" />
<tiles:useAttribute id="selectedIndexStr" name="selectedIndex" ignore="true"
classname="java.lang.String" />
....
String requestLastSelectedIndex = request.getParameter(parameterName);
String sessionLastSelectedIndex = (String)session.getAttribute(parameterName);
...
if((requestLastSelectedIndex==null) &&
(sessionLastSelectedIndex==null))
{
selectedIndex = 0;
}
else if(requestLastSelectedIndex==null)
{
selectedIndex = Integer.parseInt(sessionLastSelectedIndex);
}
else
{
selectedIndex = Integer.parseInt(requestLastSelectedIndex);
session.setAttribute(parameterName, requestLastSelectedIndex);
}
So for each nodeX (where X=1..5) on the left side of the application, there is a
<definition></definition> that gets represented with the following format (5 unique
times):
<definition name="nodeX.tabs.page" path="/secure/layout/classicLayout.jsp">
<put name="title" value="nodeX tabs" />
<put name="header" value="" />
<put name="footer" value="" />
<put name="menu" value="" />
<put name="body" value="nodeX.tabs.body" />
</definition>
<definition name="nodeX.tabs.body" path="/secure/layout/tabsLayout.jsp" >
<put name="selectedIndex" value="0" />
<put name="parameterName" value="nodeXLastSelectedTab" />
<putList name="tabList" >
<item value="Tab 1" link="/secure/nodeX_1_Tab.jsp" />
<item value="Tab 2" link="/secure/nodeX_2_Tab.jsp" />
......
</putList>
</definition>
This setup works fine when on the left side all nodes ***uniquely reference their
appropriate <definition>*** (node1...node5) because the parameterName's value is
nodeXLastSelectedTab (where X=1..5). And thus what parameter/attribute gets inserted
into the request/session stated above is unique:
session.setAttribute(node3LastSelectedTab, "2") if I clicked on node3 and selected the
2nd tab on the right side.
Since the nodes on the left side are data driven, one could conceivably have two nodes
that reference the same <definition>. So consider the example of when there are 6
nodes. The problem arises when I click the 3rd node and choose the 2nd tab (as I
describe above) and now I click on a sixth node (node6) ***for the first time*** who
programmatically references the <definition> of node3. So the session/request
getAttribute/getParameter will use node3LastSelectedTab to lookup and **inproperly**
shows the 2nd tab.
Is there a "struts way" to solve this? I know I could always set some attribute on the
session inside the Action's java code and rewrite the above code as
String requestLastSelectedIndex = request.getParameter(parameterName +
session.getAttribute("MODEL_ID"));
String sessionLastSelectedIndex = (String)session.getAttribute(parameterName +
session.getAttribute("MODEL_ID"));
....
session.setAttribute(parameterName + session.getAttribute("MODEL_ID"),
requestLastSelectedIndex);
But I don't want to be straying off something that struts may have already solved.
Plus, is there a struts way to remember the last selected tab? I may be doing that
incorrect and led me down this path to begin with.
Thanks for your time and patience...Jim