Greetings all, I'm a JSP newbie so I'm hoping someone can point out where I'm going wrong here and give me a helping hand.
The situation is that I'm iterating through a collection of objects and outputting html accordingly. The problem is that I'm using a <jsp:useBean> to pass the object to an included file and so I'm only getting to see the first element of the collection.
Code will help. The iterating code -
(which seems horribly ugly now that I'm showing it to people!)
and the included file -
I think I'm getting the same output each time because after the first iteration the bean is instantiated and so useBean doesn't create a new one, no? I know I can't use a nested param tag because they're only for string parameters.
So am I into custom tag territory? That seems overkill for just writing a bit of text. I also don't want to inline the markup from the included file as that defeats the purpose of separating it out in the first place.
Can't help but feel I'm missing something straightforward with this one. Any pointers gratefully received. [ May 03, 2007: Message edited by: Ross Hendry ]
It looks like you are simply copying properties from your iteration item ("file") into another container for passing to the included file. Why the copying? Why not directly reference whatever "file" points to as it already contains the values you need?
Also, are you using JSP 2.0? If so, tag files would be a lot better than included JSP fragments for this purpose.
Joined: May 03, 2007
Tag files did it! Time to order a more up-to-date book.
I was trying to pass the entity to a fragment to output some html. I'd tried passing it directly instead of copying to another container but hadn't managed that as, IIRC, the tags would only allow a string value to be passed.
Two minutes after reading your post this morning I had converted the fragment to a tag file and got it working precisely how I'd intended. Many thanks.