aspose file tools*
The moose likes JSP and the fly likes Problem with EL returning wrong object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with EL returning wrong object" Watch "Problem with EL returning wrong object" New topic
Author

Problem with EL returning wrong object

Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
Hi,

I am trying to set up a simple JSP page on Tomcat 5.5.4 using JSTL-standards-1.1.2. Here is the problem I am having. I think it is a bug in commons-el.

My session scope contains an object (paginator) which has a property "itemsforpage" which returns a List:



I am trying to iterate over this list like this:



When I try to access the page, I am getting an exception:



which says that it doesn't know how to iterate over the items I specified.
${paginator.itemsforpage}. I did some debugging and I found that the object it is dealing with is actually of type Paginator (not List)!!

It is as if I had items="${paginator}" instead of items="${paginator.itemsforpage}". However, the paginator.getItemsforpage() method is getting called.

1) Why is commons-el evaluating this expression to the wrong object? I think this is a bug.

2) Why is it using that commons-el expression evaluator (comes with Tomcat) instead of JSTL 1.1? Can I force it to use the real JSTL standards.jar?

Thanks
Geoffrey


Sun Certified Programmer for the Java 2 Platform
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
PS I tried this with Tomcat 5.0.30 and had the same problem.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
To answer my own question, in case anyone comes here with the same problem..

I found the problem. It was not the <c:forEach> tag. It was something in a completely different area of the page. I had this in my JSP:



which is wrong because "paginator" is not a collection. I should have had:



with this it works fine.

BUT: The real problem is that the error message is extremely misleading!! The problem had nothing to do with <c:forEach>, yet the error message indicated that it did!! This cost me 6 hours of time!!!

Someone should really fix this misleading error message!!!

Grr...
Geoffrey
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61063
    
  66

That is odd. Thanks for posting what you discovered.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It would be interesting to see the generated servlet code to see what really happened.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: Problem with EL returning wrong object