• Post Reply Bookmark Topic Watch Topic
  • New Topic

jstl object retreiv question

 
Jason Rodrigues
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have simple question I have a collection in the session
How do I retrieve the first element

<%
Collection test = new ArrayList();
...

request.getSession().setAttribute("tree",test);
%>


if I do
<c ut value="${tree.get(0)}"/> it doesnt like it . Any suggestions
[ March 07, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65531
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously since you cannot call arbitrary methods with the EL (nothing to do with the JSTL, by the way), calling get() is not going to work.

So answer your own question: if "tree" were any array how would you do it?
 
Jason Rodrigues
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true it has nothing to do with jstl
but i figured the way one would access it would be ${tree[0].name}
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65531
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So did that work for you? (The answer is of course, yes. The EL accesses elements in a collection using array syntax whether the object is truly an array or if it is a member of the Collection classes).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!