This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL/EL Nested expression (within nested forEach) Issue

 
Ken Hartz
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the below code, let's say that ${row.tool_name} equals the tool name Subversion, I would like to use that tool_name value in the second forEach loop so I would have items="${Subversion.rows}". I realize the below syntax is incorrect, I've tried using different bracket combinations with no success. Is it possible to accomplish what I'm trying to do?

<c:forEach var="row" items="${tools.rows}" varStatus="counter">

<tr><td><c:out value="${row.tool_name}"/></td></tr>

<c:forEach var="row2" items="${${row.tool_name}.rows}" varStatus="counter2">
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the object type behind tool_name has a getRows() method which returns Iterable, then just do ${row.tool_name.rows}.
 
Ken Hartz
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I initially thought would work but I get an HTTP 500 (internal server) error. The value of ${row.tool_name} does have a getRows() behind it because when I put in the hard-coded value (for instance putting in ${Subversion.rows} instead of ${row.tool_name.rows} I do get rows returned. I've also checked to make sure the values of ${row.tool_name} I'm getting in the first loop look correct (Subversion, ClearCase etc...). In the servlet I do a request.setAttribute("tools", tools.findTools()); and the findTools method returns a Result object. Any other ideas of what the issue might be?
 
Ken Hartz
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I did not mention which may be the root of the issue, is that in the servlet I do a request.setAttribute for each tool's data like the following

for (String toolName : toolNames) {
request.setAttribute(toolName, outageData.findOutageRPToutages(reqdate1, reqdate2, toolName));
}

The above ends up doing something like request.setAttribute("Subversion", Result); for all the tools in the toolNames collection

So I'm working with 2 different type of Result objects that are request Attributures in the JSP, one is named "tools" and it is simply rows of the different tool names from one database table, the other Attributes are all Result objects of each tool's data and the name of those Attributes in the JSP are hte same as the tool name such as "Subversion".



 
Ken Hartz
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ended up solving this by taking a different approach. What I did was just set an attribute of a Result set of data from all tools for the second/nested <c:forEach loop and then I loop through all tools' data in that second/nested loop and simply check to see if it's the current tool from the first <c:forEach loop's tool_name value. This is working fine but thank you for the help!
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would let review your complete code by a more experienced developer.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic