• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Julien Roubieu
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use composition instead of inheritance and make the list a property of the bean, you could achieve this with EL.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic