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 Both bean and List, how to get a property with EL ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Both bean and List, how to get a property with EL ?" Watch "Both bean and List, how to get a property with EL ?" New topic
Author

Both bean and List, how to get a property with EL ?

Julien Roubieu
Greenhorn

Joined: Nov 16, 2005
Posts: 10
Hello,

I have an object that implements List and that also have some getters that I would like to access using EL.

However, when I write in my jsp page :


I get the following exception:
javax.servlet.jsp.el.ELException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.

Is there a way to retrieve the value of a property myObject using EL ?

Thanks,
Julien
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

No, by creating a Frankensteins's Monster of an object that exhibits both the attributes of a List and a bean, you have broken the EL contract.

Section JSP.2.3.4 clearly states the order in which values are introspected. The check for List/Map happens before the object is treated as a bean, which is the fall-through case when the object doesn't match anything else.

An object cannot be treated as both. And that makes perfect sense; otherwise ambiguous and anomolous behavior is much too likely.


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

Joined: Dec 11, 2004
Posts: 13410

If you use composition instead of inheritance and make the list a property of the bean, you could achieve this with EL.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Both bean and List, how to get a property with EL ?