• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing forEach-variable within scriptlets

 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,

I have a problem to access the forEach-variable within scriptlets.

The request-attribute orderList contains objects from the type reports.ejb.OrderTO.

Here is a snippet from my JSP:

<%@ page import="reports.ejb.OrderTO" %>
<% OrderTO o = new OrderTO(); %>
<table border="1">
<c:forEach var="order" items="${orderList}" >
<% Object x = pageContext.findAttribute("order");
if (x == null) { System.out.println("null"); }
else { System.out.println("not null"); }
if (x instanceof reports.ejb.OrderTO)
{ System.out.println("instanceof"); }
else { System.out.println("not instanceof"); }
o = (OrderTO) x;
%>
</c:forEach>
</table>

And this is the result:

not null
not instanceof
java.langClassCastException: reports.ejb.OrderTO

With the EL expressions ${order.article} or ${order.description} I can access my transfer-object OrderTO within the loop, but through scriptlets it's not possible.

Is the scriptlet-code "pageContext.findAttribute("order");" really correct to access the variable order from <c:forEach var="order"...>?

Or is there another way how I can access the forEach-variable order through scriptlets?

Kind regards

Oliver
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The collection is not full of reports.ejb.OrderTO objects but is instead full of something else. Perhaps it's another similar object in your code base.

Try running in debug mode or outputting the object to the page or your console to determine what type of object you're really dealing with.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic