Meaningless Drivel is fun!*
The moose likes JSP and the fly likes What is Correct EL Syntax for ArrayList Bean Property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "What is Correct EL Syntax for ArrayList Bean Property" Watch "What is Correct EL Syntax for ArrayList Bean Property" New topic
Author

What is Correct EL Syntax for ArrayList Bean Property

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1478
    
    1
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1478
    
    1
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

That'll keep the code much more readable and clear. :thumbup:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What is Correct EL Syntax for ArrayList Bean Property