• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

custom tag parameters

 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65125
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic