Differences between revisions 1 and 2
Revision 1 as of 2006-07-22 03:00:57
Size: 1472
Comment:
Revision 2 as of 2009-09-20 23:11:56
Size: 1476
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 51: Line 51:
 * [http://www-128.ibm.com/developerworks/java/library/j-jstl0415/ A JSTL primer: Message Resources]
 * [http://www.systemmobile.com/?p=200 Struts Message Resources]
 * [[http://www-128.ibm.com/developerworks/java/library/j-jstl0415/|A JSTL primer: Message Resources]]
 * [[http://www.systemmobile.com/?p=200|Struts Message Resources]]

<bean:message> is used to display a localized and possibly parameterised message from a property file bundled with application.

Common Setup

Resource files should be names according to locale and country, like:

  • Messages_en.properties -- English language
  • Messages_fr.properties -- French language
  • Messages_fr_CA.properties -- French language, Canadian dialect

Struts Taglib

struts-config.xml:

<message-resources parameter="com.acme.webboard.Messages"/>

JSP file:

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<%-- No arguments --%>
<bean:message key="webboard.greeting"/>

<%-- Passing arguments to a message in a JSP2.0 container --%>
<bean:message key="webboard.greeting" arg0="${user.name}"/>

JSTL

web.xml:

<context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>com.acme.webboard.Messages</param-value>
</context-param>

JSP file:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<%-- No arguments --%>
<fmt:message key="webboard.greeting"/>

<%-- Passing arguments to a message --%>
<fmt:message key="webboard.greeting"/>
  <fmt:param value="${user.name}"/>
</fmt:message>

More information:

JSTLTagsBeanMessage (last edited 2009-09-20 23:11:56 by localhost)