• 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

custom tag parameters

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic