aspose file tools
The moose likes JSP and the fly likes jstl-el problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "jstl-el problem" Watch "jstl-el problem" New topic
Author

jstl-el problem

vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
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

Joined: Sep 07, 2008
Posts: 676


Hi,

What is your listName type .??


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88



this listName is a arraylist
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

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()>.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
Hi there,

then what should be solution if i need to get such functionality
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1005
Two possible solutions
- the empty keyword
- the fn:length function (not available in JSTL1.0)

Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


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

Joined: Jan 01, 2009
Posts: 874


Stefan beat me !!
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 356
you can use [] operator instead of . operator
Using this you can use ArrayList and Arrays in EL.


Thanks,
Shailesh
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

you can use [] operator instead of . operator


how would that helps the current problem?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

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

Joined: Jul 10, 2008
Posts: 356
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl-el problem
 
Similar Threads
ArrayList issue
when are broken unit tests ok?
Majji Exm1 :
custom taglib problem
sublist of arraylist???