Forums Register Login

Using resource bundle as input for a custom tag

+Pie Number of slices to send: Send
I've written a custom tag that is invoked like this:
<custom:tag title="a title"/>
And I'm trying to accomplish the following in my JSP page:
<fmt:bundle base="messages">
<custom:tag title="<fmt:message key="foo.key"/>"/>
</fmt:bundle>
That is, I want to use a message from a resource bundle as input to my custom JSP tag.
Is this at all possible (hopefully in a straightfoward way)??
Thanks,
Jon
+Pie Number of slices to send: Send
You didn't mention whether this was under JSP 1.2 or JSP 2.0. If the latter,
something along the lines of the following might work (completely untested!):

Under JSP 1.2, perhaps:
+Pie Number of slices to send: Send
Excellent! Since the first way didn't work (I'm using tomcat 5.x, isn't that jsp 2.0?), I wound up using a hybrid of your ideas:

And just made my custom tag class look for a variable named "ia.title" in the pageContext.
Thanks so much!!
Jon
+Pie Number of slices to send: Send
 

I'm using tomcat 5.x, isn't that jsp 2.0?


Yes.


And just made my custom tag class look for a variable named "ia.title" in the pageContext.


Just be aware that that creates a strong coupling between your tag and its usage on the page, which could limit the reusability of the tag. While that's not always a bad thing, just be aware of it and make sure to use this type of technique only where appropriate.
+Pie Number of slices to send: Send
Good advice! To try to keep the coupling as low as possible, I've gone ahead and made the "title" attribute a non-required attribute in the TLD, so users can do either:

Thanks for your suggestions!
Jon
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1964 times.
Similar Threads
internationalization in JSTL
fmt: tag
Managing message Resource Bundle struts 1.3.8
Is there a way to use "prefix" with <fmt:setBundle> in JSTL format tags?
jstl objects
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:00:10.