You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Howard Moore <Ho...@datapulse.com> on 2001/06/26 10:28:54 UTC

RE: cvs commit: jakarta-struts/src/share/org/apache/struts/taglib /bean LocalStrings.properties MessageTag.java

How about adding similar support for the argX attributes? Whenever I want to
display a message that includes arguments I invariably want to get the value
of the arguments from a bean so I end up writing something like this;

<bean:message key="search.result.count" arg0="<%=
MyFormBean.getResultCount() %>"/>

I would much prefer to be able to write this; 

<bean:message key="search.result.count" name="MyFormBean"
arg0="resultCount"/>

In this case the resource key is a static string and the arguments are
properties of a bean. For me this is the most common way I would like to use
messages with arguments. Of course, if the key attribute were replaced with
the property attribute then all the parameters would be obtained from the
bean. 

> -----Original Message-----
> From: martinc@apache.org [mailto:martinc@apache.org]
> Sent: 26 June 2001 06:18
> To: jakarta-struts-cvs@apache.org
> Subject: cvs commit:
> jakarta-struts/src/share/org/apache/struts/taglib/bean
> LocalStrings.properties MessageTag.java
> 
> 
> martinc     01/06/25 22:18:26
> 
>   Modified:    doc      struts-bean.xml
>                src/share/org/apache/struts/taglib/bean
>                         LocalStrings.properties MessageTag.java
>   Log:
>   Added 'name', 'property' and 'scope' attributes to 
> <bean:message> so that
>   the message resource key can be obtained dynamically from a bean.
>   
>   Revision  Changes    Path
>   1.5       +44 -2     jakarta-struts/doc/struts-bean.xml
>   
>   Index: struts-bean.xml
>   ===================================================================
>   RCS file: /home/cvs/jakarta-struts/doc/struts-bean.xml,v
>   retrieving revision 1.4
>   retrieving revision 1.5
>   diff -u -r1.4 -r1.5
>   --- struts-bean.xml	2001/05/09 19:31:00	1.4
>   +++ struts-bean.xml	2001/06/26 05:18:22	1.5
>   @@ -444,6 +444,10 @@
>        <p>Retrieves an internationalized message for the 
> specified locale,
>        using the specified message key, and write it to the 
> output stream.
>        Up to five parametric replacements (such as "{0}") may 
> be specified.</p>
>   +
>   +    <p>The message key may be specified directly, using 
> the <code>key</code>
>   +    attribute, or indirectly, using the <code>name</code> and
>   +    <code>property</code> attributes to obtain it from a bean.</p>
>        </info>
>    
>        <attribute>
>   @@ -505,11 +509,13 @@
>    
>        <attribute>
>          <name>key</name>
>   -      <required>true</required>
>   +      <required>false</required>
>          <rtexprvalue>true</rtexprvalue>
>          <info>
>          <p>The message key of the requested message, which must have
>   -      a corresponding value in the message resources.</p>
>   +      a corresponding value in the message resources. If 
> not specified,
>   +      the key is obtained from the <code>name</code> and
>   +      <code>property</code> attributes.</p>
>          </info>
>        </attribute>
>    
>   @@ -522,6 +528,42 @@
>          selected <code>Locale</code> object is stored.  If 
> not specified,
>          the default name (the value of the 
> <code>Action.LOCALE_KEY</code>
>          constant string) is used.</p>
>   +      </info>
>   +    </attribute>
>   +
>   +    <attribute>
>   +      <name>name</name>
>   +      <required>false</required>
>   +      <rtexprvalue>true</rtexprvalue>
>   +      <info>
>   +      <p>Specifies the attribute name of the bean whose 
> property is accessed
>   +      to retrieve the value specified by <code>property</code> (if
>   +      specified).  If <code>property</code> is not 
> specified, the value of
>   +      this bean itself will be used as the message 
> resource key.</p>
>   +      </info>
>   +    </attribute>
>   +
>   +    <attribute>
>   +      <name>property</name>
>   +      <required>false</required>
>   +      <rtexprvalue>true</rtexprvalue>
>   +      <info>
>   +      <p>Specifies the name of the property to be accessed 
> on the bean
>   +      specified by <code>name</code>.  This value may be a 
> simple, indexed,
>   +      or nested property reference expression.  If not 
> specified, the value
>   +      of the bean identified by <code>name</code> will 
> itself be used as the
>   +      message resource key.</p>
>   +      </info>
>   +    </attribute>
>   +
>   +    <attribute>
>   +      <name>scope</name>
>   +      <required>false</required>
>   +      <rtexprvalue>true</rtexprvalue>
>   +      <info>
>   +      <p>Specifies the variable scope searched to retrieve 
> the bean specified
>   +      by <code>name</code>.  If not specified, the default 
> rules applied by
>   +      <code>PageContext.findAttribute()</code> are applied.</p>
>          </info>
>        </attribute>
>    
>   
>   
>   
>   1.13      +1 -0      
> jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalSt
> rings.properties
>   
>   Index: LocalStrings.properties
>   ===================================================================
>   RCS file: 
> /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/be
> an/LocalStrings.properties,v
>   retrieving revision 1.12
>   retrieving revision 1.13
>   diff -u -r1.12 -r1.13
>   --- LocalStrings.properties	2001/05/09 19:31:11	1.12
>   +++ LocalStrings.properties	2001/06/26 05:18:24	1.13
>   @@ -8,6 +8,7 @@
>    include.read=Exception reading resource {0}: {1}
>    include.url=Cannot create include URL: {0}
>    message.message=Missing message for key {0}
>   +message.property=Property for message key must be a String
>    message.resources=Missing resources attribute {0}
>    page.selector=Invalid page context selector {0}
>    parameter.get=No parameter {0} was included in this request
>   
>   
>   
>   1.5       +64 -5     
> jakarta-struts/src/share/org/apache/struts/taglib/bean/MessageTag.java
>   
>   Index: MessageTag.java
>   ===================================================================
>   RCS file: 
> /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/be
> an/MessageTag.java,v
>   retrieving revision 1.4
>   retrieving revision 1.5
>   diff -u -r1.4 -r1.5
>   --- MessageTag.java	2001/02/20 01:48:45	1.4
>   +++ MessageTag.java	2001/06/26 05:18:25	1.5
>   @@ -1,7 +1,7 @@
>    /*
>   - * $Header: 
> /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/be
> an/MessageTag.java,v 1.4 2001/02/20 01:48:45 craigmcc Exp $
>   - * $Revision: 1.4 $
>   - * $Date: 2001/02/20 01:48:45 $
>   + * $Header: 
> /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/be
> an/MessageTag.java,v 1.5 2001/06/26 05:18:25 martinc Exp $
>   + * $Revision: 1.5 $
>   + * $Date: 2001/06/26 05:18:25 $
>     *
>     * 
> ====================================================================
>     *
>   @@ -82,7 +82,7 @@
>     * <code>ActionServlet</code> implementation.
>     *
>     * @author Craig R. McClanahan
>   - * @version $Revision: 1.4 $ $Date: 2001/02/20 01:48:45 $
>   + * @version $Revision: 1.5 $ $Date: 2001/06/26 05:18:25 $
>     */
>    
>    public class MessageTag extends TagSupport {
>   @@ -196,6 +196,48 @@
>    
>    
>        /**
>   +     * Name of the bean that contains the message key.
>   +     */
>   +    protected String name = null;
>   +
>   +    public String getName() {
>   +        return (this.name);
>   +    }
>   +
>   +    public void setName(String name) {
>   +        this.name = name;
>   +    }
>   +
>   +
>   +    /**
>   +     * Name of the property to be accessed on the specified bean.
>   +     */
>   +    protected String property = null;
>   +
>   +    public String getProperty() {
>   +        return (this.property);
>   +    }
>   +
>   +    public void setProperty(String property) {
>   +        this.property = property;
>   +    }
>   +
>   +
>   +    /**
>   +     * The scope to be searched to retrieve the specified bean.
>   +     */
>   +    protected String scope = null;
>   +
>   +    public String getScope() {
>   +        return (this.scope);
>   +    }
>   +
>   +    public void setScope(String scope) {
>   +        this.scope = scope;
>   +    }
>   +
>   +
>   +    /**
>         * The session scope key under which our Locale is stored.
>         */
>        protected String localeKey = Action.LOCALE_KEY;
>   @@ -227,6 +269,20 @@
>         */
>        public int doStartTag() throws JspException {
>    
>   +        String key = this.key;
>   +        if (key == null) {
>   +            // Look up the requested property value
>   +            Object value =
>   +                RequestUtils.lookup(pageContext, name, 
> property, scope);
>   +            if (value != null && !(value instanceof String)) {
>   +                JspException e = new JspException
>   +                    (messages.getMessage("message.property", key));
>   +                RequestUtils.saveException(pageContext, e);
>   +                throw e;
>   +            }
>   +            key = (String)value;
>   +        }
>   +
>    	// Construct the optional arguments array we will be using
>    	Object args[] = new Object[5];
>    	args[0] = arg0;
>   @@ -237,7 +293,7 @@
>    
>    	// Retrieve the message string we are looking for
>    	String message = RequestUtils.message(pageContext, this.bundle,
>   -                                              
> this.localeKey, this.key, args);
>   +                                              
> this.localeKey, key, args);
>    	if (message == null) {
>    	    JspException e = new JspException
>    		(messages.getMessage("message.message", key));
>   @@ -267,6 +323,9 @@
>    	arg4 = null;
>    	bundle = Action.MESSAGES_KEY;
>    	key = null;
>   +	name = null;
>   +	property = null;
>   +	scope = null;
>    	localeKey = Action.LOCALE_KEY;
>    
>        }
>   
>   
>   
>