• Post Reply Bookmark Topic Watch Topic
  • New Topic

jstl-el problem  RSS feed

 
vijay shanker
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I want to test on the size of a list;

the folllowing didn't work:



i get error mentioning
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.


Any idea on how this can be done?
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

What is your listName type .??

 
vijay shanker
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



this listName is a arraylist
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vijay shanker wrote:

Unfortunately, you can't do this using EL, the right part after DOT is either bean property or hash map key.
Use JSTL <fn:length()>.
 
vijay shanker
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

then what should be solution if i need to get such functionality
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two possible solutions
- the empty keyword
- the fn:length function (not available in JSTL1.0)

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vijay,

Use <c:when test="${empty listName}" > to check the size is 0.

If you want to check for other values (size > 0 ) , put this ArrayList in a bean and in bean define size property and set size property to ArrayList.size and use it as EL in JSP.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stefan beat me !!
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use [] operator instead of . operator
Using this you can use ArrayList and Arrays in EL.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use [] operator instead of . operator


how would that helps the current problem?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:
you can use [] operator instead of . operator
how would that helps the current problem?

May be he wants to suggest something like this,

Bust this shouldn't be the approach
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I am thinking he want want value from ArrayList,
But he want size of arrayList, I thing we can not get size of arraylist in EL.
Of course we can do Like,
List is empty ${list[0] == null}
but as Sagar says, that is not correct approach because arrayList can contain null 0th element.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!