Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing an object parameter to an included file

 
Ross Hendry
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ross Hendry:
The problem is that I'm using a <jsp:useBean> to pass the object to an included file


You'll have to expand on exactly what you're trying to do here becasue whatever it is, <jsp:useBean> probably isn't the way to do it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On further inspection I see some red flags.

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.
 
Ross Hendry
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic