code_junkie

Struts 1.3: How to set a default Locale in a web app?

Nov 12th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <context-param>
  2. <param-name>LOCALE</param-name>
  3. <param-value>en-GB</param-value>
  4. </context-param>
  5.  
  6. java.util.Enumeration<String> setout = servletContext.getInitParameterNames();
  7. while (setout.hasMoreElements()) {
  8. String paramName = setout.nextElement();
  9. configProperties.put(paramName, servletContext.getInitParameter(paramName));
  10. }
  11.  
  12. import javax.servlet.ServletContext;
  13. import javax.servlet.ServletContextEvent;
  14. import javax.servlet.ServletContextListener;
  15.  
  16. public class AppContextListener implements ServletContextListener {
  17. @Override
  18. public void contextDestroyed(ServletContextEvent event) { /* empty. */ }
  19.  
  20. @Override
  21. public void contextInitialized(ServletContextEvent event) {
  22. /*
  23. * Default locale
  24. */
  25. ServletContext sc = event.getServletContext();
  26. sc.setAttribute(org.apache.struts.Globals.LOCALE_KEY, "pt_BR");
  27. }
  28. }
  29.  
  30. Texts_en_GB.properties
  31. Texts_pt_BR.properties
  32. Texts.propertiers ( <-- this one will be selected when no resources for requested language could be found)
  33.  
  34. <message-resources key="Texts" parameter="com.mycompany.Texts" null="false"/>
  35.  
  36. <message-resources key="Texts" parameter="com.mycompany.Texts" null="false">
  37. <set-property key="mode" value="JSTL" />
  38. </message-resources>
Add Comment
Please, Sign In to add comment