• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display ArrayList size using JSTL?

 
Thomas Autera
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am trying to display an ArrayList size. The ArrayList has been stored as a request attribute called "units". When I used the fmt syntax below I get an error.

<fmt:formatNumber value="${units.size}" type="number" pattern="###,##0" />

Here's the error:
An error occurred while evaluating custom action attribute "value" with value "${units.size}": 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. (null)

Thanks lots for your time and expertise!

Tom
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the size() method of the object is not bean-patterned, in which case it would be getSize(), it is not accessible via the EL.

If you are using JSP 2.0 and JSTL 1.1, there is a JSTL function to obtain this value. Under JSP 1.2 and JSTL 1.0, if you need this value on-page, your servlet controller will have to set it as a separate scoped variable.
 
Thomas Autera
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Thanks for your input. I am using JSP 1.0 and JSTL 1.1, but I have decided to generate another request attribute containing an Interger object, which will have the number I'm looking to display. I did not know JSTL functions existed until you mentioned them. The book I have "JSTL IN ACTION", does not mention JSTL fucntions. Thanks for the education!

I did find some more info on the same issue I am running up against where the fellow that posted was wrestling with the same issue.:
http://forum.java.sun.com/wireless/thread.jsp?thread=511513&forum=45&message=2434169

Again thanks for your help and time!

Tom
 
Thomas Autera
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry correction see bold:

Bear,

Thanks for your input. I am using JSP 2.0 and JSTL 1.1, but I have decided to generate another request attribute containing an Interger object, which will have the number I'm looking to display. I did not know JSTL functions existed until you mentioned them. The book I have "JSTL IN ACTION", does not mention JSTL fucntions. Thanks for the education!

I did find some more info on the same issue I am running up against where the fellow that posted was wrestling with the same issue.:
http://forum.java.sun.com/wireless/thread.jsp?thread=511513&forum=45&message=2434169

Again thanks for your help and time!

Tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic