wood burning stoves*
The moose likes Struts and the fly likes Help with an c:forEach and html:links Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Help with an c:forEach and html:links" Watch "Help with an c:forEach and html:links" New topic
Author

Help with an c:forEach and html:links

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I am trying to iterate over an ArrayList of beans and build html:links accordingly with the correct parameters. Here is how I retrieve and build my ArrayList:



Issues has a getter for ticket.

And then in my JSP:



The error I am getting when forwarded to the JSP is:



So am I doing something wrong/stupid here or what? Any help is appreciated.

Thanks.
[ August 11, 2004: Message edited by: Gregg Bolinger ]

GenRocket - Experts at Building Test Data
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4447
    
    5

try not using EL for paramName and paramProperty.

paramName="item"
paramProperty="ticket"

Also, I wouldn't specify paramScope="request" unless you're sure that the bean "item" will be in the request context.
[ August 11, 2004: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Junilu Lacar:
try not using EL for paramName and paramProperty.

paramName="item"
paramProperty="ticket"

Also, I wouldn't specify paramScope="request" unless you're sure that the bean "item" will be in the request context.

[ August 11, 2004: Message edited by: Junilu Lacar ]


That didn't work either. Now I get:



Before, when I was using EL, it at least knew I was looking for an Issue object. But now it doesn't event know what item is it seems.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ok, I think I know why it won't work. I just can't figure out a good way to make it work.

Struts taglibs don't work with JSTL tags when EL is involved. Basically, the html:link tag I am using is looking for my Issue object in some scope rather than looking at the current item pulled by my forEach tag for the Issue object.

Now, what can I do to make this work better? Should I be building list of Issues differently?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4447
    
    5

Originally posted by Gregg Bolinger:
Struts taglibs don't work with JSTL tags when EL is involved.


From the error messages, it seems to be working fine with EL:

paramName="${item}"
paramScope="request"

gives you

"Cannot find bean com.intrustbank.anykey.beans.dao.Issue@1d592a in scope request"

Which indicates that "${item}" is being evaluated to item.toString() which evaluates to com.intrustbank.anykey.beans.dao.Issue@1d592a

Of course, this is not the correct attribute key (there's no attribute "com.intrustbank.anykey.beans.dao.Issue@1d592a" in any context), so the tag won't find anything whereas using paramName="item" gives you the error "Cannot find bean item in scope request"

Which means it's looking for the correct attribute key ("item"). This also tells me that you either left paramScope="request" in the tag or that the html:link tag fails when it can't find "item" after searching the request context. I believe the c:forEach will put the variable in the page Context, not the request context.

If you really think it's a problem with the tag libraries and EL, make sure you are using the EL-aware struts-el.jar
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

This also tells me that you either left paramScope="request" in the tag

All is well now. I would suspect that if I put paramScope="page" it would have worked as well since, as you said:

I believe the c:forEach will put the variable in the page Context, not the request context.

But I'm not going to worry about it since it is working now. Thanks a million.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with an c:forEach and html:links
 
Similar Threads
Iterating <c:foreach> to get values from sublist
jstl c:out tag does not display the value in the list
Populating each row of a Column with combo boxes containing values from database
Displaying simple read-only tabular data
Problem filling Select from Database - c:forEach