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

  • SEARCH
  • Home
  • 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 8307317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:30:07+00:00 2026-06-08T18:30:07+00:00

I was adapting the code at http://displaytag.svn.sourceforge.net/viewvc/displaytag/trunk/displaytag/src/main/java/org/displaytag/localization/I18nWebworkAdapter.java?revision=1173&view=markup that gets the i18n resource from the

  • 0

I was adapting the code at http://displaytag.svn.sourceforge.net/viewvc/displaytag/trunk/displaytag/src/main/java/org/displaytag/localization/I18nWebworkAdapter.java?revision=1173&view=markup that gets the i18n resource from the key in Displaytag (see code below).

I was wondering if this is the cleanest approach (I dislike the iterator there). The only alternative I see, however, is getting the Action from the ActionInvocation (ActionContext.getContext().getActionInvocation().getAction()) and relying on a cast to ActionSupport to get the resource (which implements TextProvider). This doesn’t seem very safe, though (action may not extend actionsupport).

Do you have any other suggestions?

/**
 * @see I18nResourceProvider#getResource(String, String, Tag, PageContext)
 */
public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext)
{

    // if resourceKey isn't defined either, use defaultValue
    String key = (resourceKey != null) ? resourceKey : defaultValue;

    String message = null;
    OgnlValueStack stack = TagUtils.getStack(pageContext);
    Iterator iterator = stack.getRoot().iterator();

    while (iterator.hasNext())
    {
        Object o = iterator.next();

        if (o instanceof TextProvider)
        {
            TextProvider tp = (TextProvider) o;
            message = tp.getText(key, null, null);

            break;
        }
    }

    // if user explicitely added a titleKey we guess this is an error
    if (message == null && resourceKey != null)
    {
        log.debug(Messages.getString("Localization.missingkey", resourceKey)); //$NON-NLS-1$
        message = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY;
    }

    return message;
}
  • 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-06-08T18:30:08+00:00Added an answer on June 8, 2026 at 6:30 pm

    The best way would be to do it the same way the text tag does (check the implementation), or the rest of the tags do: by searching the stack.

    Also, you probably don’t mean to explicitly cast to ActionSupport, you’d likely want to check if it’s castable to a TextProvider, which is what you’re actually interested in.

    I’m not sure what your issue with the iterator is–that’s how it should be done, since your goal is to walk the stack and try with the top-most TextProvider. You may not want to stop with the top-most, depends on your needs/goals.

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

Sidebar

Related Questions

I'm adapting this progress bar:http://www.richardshepherd.com/tv/audio/ to work with my playlist code, but I can't
What's the best practise when adapting C-style functions which return a true/false to Java?
So, I am adapting some code I found online to suit my needs. However,
I'm using GraniteDS Actionscript code generation templates that let's me take a Java object
I have been adapting our code in preparation of moving our code to the
I'm playing with stopPropagation , adapting code from an MDC doc . Here's the
I have a huge issue of adapting the code into C++Builder. What is the
I wrote this simple test code, by adapting a piece from a book, to
I have a sectioned UITableView using dictionaries adapting code from a tutorial (I don't
I'm adapting some code originally written for Windsor to use StructureMap. In the Windsor

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.