title: Access resource bundle outside struts action class
body: <p>There are several ways to handle resource bundle using Struts 2.3 framework. This includes using certain UI tags in the View class or <code>getText()</code> method in your Action class.</p>
  
  <p>However, there is no straight-forward mechanism to access this resource bundle in a java class or any other class except View and Action.</p>
  
  <p>I found two ways to access it in a java class,however, they fail to completely replace the old <code>MessageResources</code> of Struts 1.2 framework.</p>
  
  <p>Following are the two ways with drawback of each</p>
  
  <ol>
  <li><p>Using <code>ResourceBundle</code> class of <code>java.util</code> package.</p>
  
  <pre><code>Locale locale = (Locale)request.getSession().getAttribute(ConstantsFnl.LOCALE_KEY);
  ResourceBundle rb = ResourceBundle.getBundle(bundle,locale);
  message = rb.getString(key);
  </code></pre>
  
  <p>The drawback with this approach is you cannot pass an array of arguments which can be replaced in your message text.This functionality was present in Struts 1.2 with <code>MessageReosurces</code>.</p></li>
  <li><p>Using <code>DefaultTextProvider</code> of Struts 2.3 framework.</p>
  
  <pre><code>DefaultTextProvider dtp = new DefaultTextProvider();
  return dtp.getText(key, (String[])params);
  </code></pre></li>
  </ol>
  
  <p>Though this approach gives you a way to pass an array of arguments to be replaced in your message text, it does not give you a mechanism to specify the locale or specify the bundle to be searched.Again,this functionality is present in Struts 1.2 with <code>MessageResources</code> class.</p>
  
  <p>Looking for an optimum approach.Any help on this would be great. </p>