Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL forEach

 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I am trying to get this JSTL forEach tag to work with a collection. I have a UserBean that contains a collection of users, called users.

I first get a hold of the bean using <jsp:useBean> I am sure I am getting the bean ok because I can print out other attributes. Then I first tried the following to iterate over the users collection.



That hung up so then I tried this


which also hung up. Any thoughts?

Thanks,

AMD
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
opps sorry that extra quote was not in it

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:forEach items="<jsp:getProperty
name="userBean"
property="users"/>
"var="user">


Completely not valid. You cannot use an action as the attribute value of another action.

Your second notation is more along proper lines.

What does "hung up" mean?
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hung up means that I eventually get a page not found after it sits spinning for awhile.

Thanks,

AMD
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page not found?

That shouldn't have anything to so with anything on the page. After all, if it can't find it...

Do things work if you remove the action?
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes if I remove the forEach stuff the page goes ok? Does the syntax on the second try look ok?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Any errors in the logs?
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it has something to do with how I am setting the list on the form bean.

I have in my doView method of my portlet



This is what my set method looks like



When I have this code in is when it acts wackey? I am confused now.

Thanks,

AMD
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. The JSTL code was ok. For some reason it did not like it that I iniitalized the array in the form bean. As soon as I took that out it worked?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic