This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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

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

Julien Roubieu

Joined: Nov 16, 2005
Posts: 10

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 ?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60812

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

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:
subject: Both bean and List, how to get a property with EL ?
Similar Threads
Getting map values using EL in JSP
JSTL without el to bind in spring
form and html-el:form Problems
How to retrieve newly added text strings from ResourceBundle through EL ?