File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSTL/EL Nested expression (within nested forEach) Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL/EL Nested expression (within nested forEach) Issue" Watch "JSTL/EL Nested expression (within nested forEach) Issue" New topic
Author

JSTL/EL Nested expression (within nested forEach) Issue

Ken Hartz
Greenhorn

Joined: Jul 08, 2006
Posts: 14
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

Joined: Oct 08, 2006
Posts: 2458
If the object type behind tool_name has a getRows() method which returns Iterable, then just do ${row.tool_name.rows}.
Ken Hartz
Greenhorn

Joined: Jul 08, 2006
Posts: 14
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

Joined: Jul 08, 2006
Posts: 14
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

Joined: Jul 08, 2006
Posts: 14
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

Joined: Oct 08, 2006
Posts: 2458
I would let review your complete code by a more experienced developer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JSTL/EL Nested expression (within nested forEach) Issue