This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

**SOLVED** tag handler outputting localised text - how to do this?  RSS feed

Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Solved (see bottom of message).

Been trying to find out how to output localised text from my tag handler. My handler extends SimpleTagSupport. This is the road I've gone down: After some searching I found the class LocaleSupport which says:

This class may be useful to any tag handler implementation that needs to produce localized messages. For example, this might be useful for exception messages that are intended directly for user consumption on an error page.

Sounds ideal! However all 4 methods of LocaleSupport require a javax.servlet.jsp.PageContext as their first parameter. I can't find out how to get an instance of this type. calling getJspContext() in my tag handler gives me a JspContext which is a superclass of PageContext.

Hope someone can help me with this! Perhaps there's a more direct, better way?



Rather than extending from SimpleTagSupport, I extended my tag handler from BodyTagSupport. I could still specify (in the TLD file) that the handler expects an empty body. Subclasses of BodyTagSupport get access to the pageContext variable which is exactly what needs to be supplied as the first parameter to the LocaleSupport methods.
Destroy anything that stands in your way. Except this tiny ad:
ScroogeXHTML 7.2 - RTF to HTML5 / XHTML converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!