Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

In webwork.properties(as of Webwork 2.1.1),
you can now use:Struts 2, resource bundles can be associated with classes. The framework will automatically discover and load class-orientated resource bundles. You can also specify one or more global resource bundles, which would be available to all classes in the application, using either the standard properties file, or a custom listener.

Properties file

Global resource bundles can be specified in the struts.properties configuration file.

Code Block
titlestruts.properties

struts
Code Block

webwork.custom.i18n.resources=global-messages
Tip

The framework searches the class heirarchy first, then, as a last resource, checks the global resources.

Multiple Serveral resource bundles can be specified by comma separating them.
for example see webwork.properties : http://wiki.opensymphony.com/display/WW/webwork.propertiesImage Removed

Java class (thanks Drew McAuliffe):

providing a comma-separated list.

Code Block
titlestruts.properties

struts.custom.i18n.resources=global-messages, image-messages

Listener

Aside from the properties file, a Listener could also be used to load global resource bundles.

Code Block
titleActionGlobalMessagesListener.
Code Block
javajava
public class WebworkGlobalMessagesListenerActionGlobalMessagesListener implements ServletContextListener {
    private static Logger log = Logger.getLogger(WebworkGlobalMessagesListenerActionGlobalMessagesListener .class);
    private static final String DEFAULT_RESOURCE = "global-messages";

    /**
     * Uses the LocalizedTextUtil to load messages from the global
     message bundle.
     * @see
     javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Servle
     tContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
        log.info("Loading global messages from " + DEFAULT_RESOURCE);
        LocalizedTextUtil.addDefaultResourceBundle(DEFAULT_RESOURCE);
        log.info("Global messages loaded.");
    }

    /**
     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {

        // do nothing

    }

}

web.xml:
(under listeners section)

Code Block
xml
titleweb.xml
<listener>
  <listener-class>mypackagename.WebworkGlobalMessagesListener<ActionGlobalMessagesListener</listener-class>
</listener>