...
How do I set a global resource bundle?
In webwork.properties(as of Webwork 2.1.1),
you can now use:
Code Block |
---|
webwork.custom.i18n.resources=global-messages
|
Serveral resource bundles can be specified by comma separating them.
for example see webwork.properties : http://wiki.opensymphony.com/display/WW/webwork.properties
Java class (thanks Drew McAuliffe):
...
public class WebworkGlobalMessagesListener implements ServletContextListener {
private static Logger log = Logger.getLogger(WebworkGlobalMessagesListener.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)
...
<listener>
<listener-class>mypackagename.WebworkGlobalMessagesListener</listener-class>
</listener>
How do I change the error message for invalid inputted fields?
You need to create a message for that field, for example if you have a user.dob field you would use this in your messages file (see above for example on setting a global messages file):
invalid.fieldvalue.user.dob=Please enter Date of Birth in the correct format.
...