• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing an object parameter to an included file

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic