aspose file tools*
The moose likes JSP and the fly likes c:forEach is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "c:forEach is not working" Watch "c:forEach is not working" New topic
Author

c:forEach is not working

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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 cut 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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60063
    
  65

Have you looked at the generated HTML source to see what, if anything, is being emitted?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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 cut 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 cut tag.

I must be close, right?

Ideas?

Thanks again.

Mike
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60063
    
  65

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: <cut><cut><cut><cut><cut><cut><cut>

If you are still seeing <cut> 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
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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 cut tag in the page source. But the value is ' '. Nothing gets printed. No errors occur either.

Thanks.

-- Mike
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60063
    
  65

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
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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 cut tags.

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

Best,

Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:forEach is not working
 
Similar Threads
Use of deferred expressed in iteration doesn't work
JSTL forEach tag
JSTL forEach and iterating through a list
Accessing nested info via html:text
how to iterate hashmap in jsp?