Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EL Help please  RSS feed

 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have EL working in that when I create a JavaBean, I can put out the value as in ${person.name} prints out "Matt". The problem I'm having is getting EL to work with an ArrayList that exists in a java class... do I have to do something in the DD file to get this to work? How does the EL know what I'm talking about if I say ${movieList} that I mean an ArrayList that contains my movies?

I tried this with a servlet using the request.setAttribute("musicList", favoriteMusic); - but no output...

P.S. In case it is not obvious, I'm going through the HeadFirst Servlets and JSP book.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to specify anything in the DD.
How did you try to output the array ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
java.util.List favoriteMusic = new java.util.ArrayList();
favoriteMusic.add("Doors");
favoriteMusic.add("JMJ");
request.setAttribute("musicList", favoriteMusic);
%>

${musicList} will dump the content of the array
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say

an ArrayList that exists in a java class...



and


if I say ${movieList}


which do not seem compatible.

What is movieList? Is it he bean or the list?

If movieList is the bean, and let's say it has an accessor for the List getMyList(), then the reference to get the the actual list, which is a property of the bean, would be:

${movieList.myList}
[ March 09, 2006: Message edited by: Bear Bibeault ]
 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, according to page 372 of HFS&J, the servlet contains the code (slightly modified to music instead of food):


And in the JSP, you simply do the following to ouput the entire ArrayList:


or, to output a specific value:


But nothing prints out (other than "Music is:")
How do I actually 'tie' the JSP to that servlet... how does EL know which servlet has "musicList" in it?
[ March 10, 2006: Message edited by: Matt Holloway ]
 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... duh... I'm a fool. For SOME reason, I was pumping the direct JSP name into the url path, not the servlet mapping name.

It works now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so in this case musicList is the list...

The EL will search the scopes for the variable, including request scope where you placed the variable.

How are you getting to the JSP from the servlet?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!