File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:forEach is not working

 
Mike London
Ranch Hand
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • 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 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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the generated HTML source to see what, if anything, is being emitted?
 
Mike London
Ranch Hand
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • 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 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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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: <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
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • 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 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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • 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 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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic