You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by Apache Wiki <wi...@apache.org> on 2006/07/22 05:00:58 UTC

[Struts Wiki] Update of "JSTLTagsBeanMessage" by MichaelJouravlev

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.

The following page has been changed by MichaelJouravlev:
http://wiki.apache.org/struts/JSTLTagsBeanMessage

New page:
<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:
 * [http://www-128.ibm.com/developerworks/java/library/j-jstl0415/ A JSTL primer: Message Resources]
 * [http://www.systemmobile.com/?p=200 Struts Message Resources]