Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1076659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:27:36+00:00 2026-05-16T21:27:36+00:00

Is it possible to write a custom JSP tag to take an i18n message

  • 0

Is it possible to write a custom JSP tag to take an i18n message key and output the translation phrase for the given request?

Normally in JSP/JSTL, I do:

<fmt:message key="${messageKey}"><fmt:param>arg1</fmt:param></fmt:message>

And I get the translation phrase. Now I need to do the following (there’s a good reason for this):

<custom:translate key="${messageKey}" arg="arg1"/>

But I don’t know how to look up the translation in the custom tag code. The TagSupport base class provides a pageContext from which I can get a ServletRequest which has the Locale… but how do I then look up the translation for a key?

I use Spring 3.0 and in my application-context.xml, I’ve defined a ReloadableBundleMessageSource so I can call:

messageSource.getMessage(
    key, new Object[] {arg}, pageContext.getRequest().getLocale()
);

but I don’t think I can inject messageSource into a custom tag, can I? Otherwise I can instantiate a new one, but would it load my tens of thousands of translations for every call? I don’t want to resort to making messageSource a static member of a static class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:27:37+00:00Added an answer on May 16, 2026 at 9:27 pm

    I don’t do Spring, but in “plain” JSP you can just put the ResourceBundle instance in the session scope with help of a Filter or Servlet

    ResourceBundle bundle = ResourceBundle.getBundle(basename, request.getLocale());
    request.getSession().setAttribute("bundle", bundle);
    

    And treat it in JSP like any other bean in EL.

    ${bundle[messageKey]}
    

    It must be possible to have Spring to put that as a bean in the session scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a Struts2 tag to my JSP from a custom tag.
Is it possible to write custom collation functions with indexes in SQLAlchemy? SQLite for
Just wondering whether it's possible to write custom applications for Kindle 3G ?
is it possible to create a custom JSTL tag that accepts a non-string attribute?
Is it possible to write custom metadata to an JPG image using Android SDK
Supposedly it's possible to write a custom picker and integrate it with AzMan. This
I wonder if and how it is possible to write a custom protocol handler
Is it possible to write a doctest unit test that will check that an
Is it possible to write code in a Flex application that will only be
Is it possible to write to the windows logs in python?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.