aspose file tools*
The moose likes JSP and the fly likes custom tag parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "custom tag parameters" Watch "custom tag parameters" New topic
Author

custom tag parameters

Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
Hi,
I have written a custom tag that iterates through a vector of strings and lets them be printed to the jsp page.
so far I have set vector values by assigning the vector as an attribute to the pagecontext in the jsp and then retrieving the attribute in the custom tag. it works, but it still doesnt look correct to me.
Is there a more 'attractive' way to do this, such as passing the vector object as a parameter, attribute or variable to the tag.
I have done the same thing using scriptlets and beans already and want to learn how to use tags properly because use of scriptlets seems to be a big no-no.
thanks
chris


SCJP 1.2, SCJP 5, SCBCD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61589
    
  67

You can pass an object (including a Vector) to a custom tag if you have a mutator that accepts that type. Problem is, you need to use a scriptlet expression to pass it. If you are trying to completely "tagify" your page and remove scriptlets and scriptlet expressions, this may not be acceptable.
What's probably making you uncomfortable about the mechanism of placing the object on the page context for use by the tag, is that you have introduced an artificial coupling between the page and the tag, as they have to agree upon the attribute name. And even Martha would agree that that's not a good thing.
A compromise that I've used in the past has been to place the object on the page (or other, as appropriate) context, and then pass the name of the attribute as a param to the tag. This way, there are no scriplets or scriptlet expressions involved, and there is minimal coupling of the page and the tag.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
I like it!!
thanks, that was what was bothering me - because I couldnt specify what my attribute name had to be.
Will give it a try.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: custom tag parameters