views:

23

answers:

1

I need to develop a tree to display the hierarchy of categories on a retail site. For example

-Clothing
  - Men
     - Trousers
     - Shirts
  - Women

I'm working on struts and using the struts dojo plugin to use this tag :

<sx:tree id="root" label="Category">

For the other child nodes, the data is stored in a database. If I use

    .......
while( rs.next())
  {
            %>
            <sx:tree id="child1" label ="<%=rs.getString("Category")%>" />
            <%
    }
......

the compiler tells me that expressions can't be used as value for the label attribute.

Can anyone suggest a workaround or any alternative for this?

+1  A: 

I'm not too familiar with Struts 2, but looking at the documentation does the following work:

%>
<s:set name="categoryValue">
    <%= rs.getString("Category") %>
</s:set>
<sx:tree id="child1" label="#categoryValue" />
<%

That being said, it is probably a better idea to iterate over the result set and create a collection based off of it in Java code and have the JSP iterate over that collection instead of the result set. The code would end up being cleaner.

laz
Thank you very much for that. Yes I am using a collection. I had forgotten the quotes and I'd just used #categoryValue(as in your example).
ryan
Hey, it doesn't seem to work.<s:set name="categoryValue" value= "%{'<%=rs.getString("category")%>'}"></s:set><sx:treenode id="child1" label ="%{#categoryValue}"/>The error I get is "/jsp/tree.jsp(249,65) equal symbol expected"However if i give<s:set name="categoryValue" value= "%{'Test'}">, the value Test is obtained.
ryan
Shouldn't the <%= rs.getString("Category") %> be nested inside as the body of the <s:set> tag instead of as the value of the element value? Or perhaps try value="<%= rs.getString('Category') %>" instead.
laz