Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is Correct EL Syntax for ArrayList Bean Property

 
Steve Dyke
Ranch Hand
Posts: 1643
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following gives the error:

E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/Sampling/SamplingInspectionItemFaxFormV6.jsp] in application [QMSWebAppEAR]. Exception created : [javax.el.MethodNotFoundException: java.lang.NoSuchMethodException: java.util.ArrayList.get(java.lang.Long)

The bean property is an ArrayList<String> with two elements, '100','true'

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Point #1: A List seems like a spectacularly poor way to model the data. Why isn't it a bean, or at worst a Map, that associates key names with the values? Using position 1 in a List to represent a value is a really poor way to do things. The data is clearly not a list, and using magic numbers into the list to represent disparate values is not acceptable.

That said, Point #2: the notation would be ${sidocObj.samplesizedata[1]} assuming samplesizedata is the list. But don't do it this way; see above.
 
Steve Dyke
Ranch Hand
Posts: 1643
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Point #1: A List seems like a spectacularly poor way to model the data. Why isn't it a bean, or at worst a Map, that associates key names with the values? Using position 1 in a List to represent a value is a really poor way to do things. The data is clearly not a list, and using magic numbers into the list to represent disparate values is not acceptable.

That said, Point #2: the notation would be ${sidocObj.samplesizedata[1]} assuming samplesizedata is the list. But don't do it this way; see above.


Thanks Bear. I created bean properties as you suggested.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That'll keep the code much more readable and clear. :thumbup:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic