• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c:forEach is not working

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm replacing a Struts iterate tag with a JSTL forEach tag since I need to programmatically change the color of a table row depending on the value in one of the ArrayList's values.

The problem is, the forEach isn't working...nothing gets displayed.

==================================
Here's the breakdown:
==================================

I have a Struts FormBean called myBean in the session.

Inside that bean is an ArrayList called userList.

The ArrayList holds "userInfo" objects with three pieces of information about each user. Each userInfo object is a regular JavaBean with getter and setter for each of the three pieces of user information(getUserName, etc.).

In my JSTL code, I have the following declaration

(brackets removed for JavaRanch posting)

c:forEach items='${myBean.userList}' var='item'
tr
td c:out value='${item}'/ /td
/tr
c:forEach

------------

However, when this code runs, it produces nothing on the screen. I've tried various permutations (like just having '${myBean}', etc.).

The Struts action correctly shows over 50 user "userInfo" Bean objects in the userList ArrayList. (Also, the Struts iterate and bean:write tags worked on this page before I tried to substitute the forEach).

I'm guessing that I'm most likely not accessing each bean in the ArrayList correctly or something like that.

Can anyone see what's wrong with this logic above given my Struts form bean, ArrayList holding Java Beans?

Thanks very much in advance!!!

- Mike
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked at the generated HTML source to see what, if anything, is being emitted?
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

This was a great idea. Forgot to check this.

Yes, in the HTML Page Source, I have a comma-delmited list of userInfo objects in the items= part of the forEach (the fully qualified com.....userInfo@...internal Java object notation type of entry).

However, the item part, where it should print out something just says:

td c:out value='' / td

So, I guess I'm confused as to how I'm supposed to access each of the setters from the item variable.

I tried something like cout value = '${item.userName}', but that didn't work either. Same value = '' in the c:out tag.

I must be close, right?

Ideas?

Thanks again.

Mike
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike, please be sure to use UBB code tags to show what's code and what's not (as well as preserve the formatting).

And there's no need to omit angle brackets. See: <c:out><c:out><c:out><c:out><c:out><c:out><c:out>

If you are still seeing <c:out> in your HTML, that means that you've got something boofed up and the JSTL isn't even being interpreted.

Have you read through the JSP FAQ entires on setting up the JSTL?
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

As I mentioned in the last posting, I am seeing a comma-delimited list of userInfo objects, so JSTL is working. I clearly have some other problem.

I must have misquoted seeing the c:out tag in the page source. But the value is ' '. Nothing gets printed. No errors occur either.

Thanks.

-- Mike
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike London:
I am seeing a comma-delimited list of userInfo objects


Describing or even paraphrasing what you are seeing is obviously not being effective. Do a View Source and cut/paste exactly what you are getting. Be sure to use UBB code tags.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

You were right after all!

I had forgotten to include the jstl tag at the top of the JSP.

I went back and double checked the page source and sure enough there were embedded c:out tags.

Thanks for your insight on this problem. Works fine now.

Best,

Mike
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic