aspose file tools*
The moose likes JSP and the fly likes Passing an object parameter to an included file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing an object parameter to an included file" Watch "Passing an object parameter to an included file" New topic
Author

Passing an object parameter to an included file

Ross Hendry
Greenhorn

Joined: May 03, 2007
Posts: 8
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

Joined: Jan 10, 2002
Posts: 61437
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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

Joined: May 03, 2007
Posts: 8
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

Joined: Jan 10, 2002
Posts: 61437
    
  67

Welcome to the Ranch!
 
jQuery in Action, 2nd edition
 
subject: Passing an object parameter to an included file