You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2002/06/23 02:07:16 UTC

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

craigmcc    2002/06/22 17:07:16

  Modified:    doc/userGuide struts-bean.xml
               src/share/org/apache/struts/taglib/bean DefineTag.java
                        LocalStrings.properties
  Log:
  Envorce the restriction that you can only set the value of the attribute
  and scripting variable created by <bean:define> in exactly one of the three
  possible ways (name/property/scope, value, or nested body content).
  
  PR: Bugzilla #8484
  Submitted by:	David M. Karr <dmkarr at earthlink.net>
  
  Revision  Changes    Path
  1.3       +23 -17    jakarta-struts/doc/userGuide/struts-bean.xml
  
  Index: struts-bean.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/doc/userGuide/struts-bean.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- struts-bean.xml	21 Feb 2002 17:49:02 -0000	1.2
  +++ struts-bean.xml	23 Jun 2002 00:07:15 -0000	1.3
  @@ -120,21 +120,27 @@
       <teiclass>org.apache.struts.taglib.bean.DefineTei</teiclass>
       <bodycontent>JSP</bodycontent>
       <info>
  -    <p>Retrieve the value of a specified bean property, and define it
  -    as an attribute (in the scope specified by the <code>toScope</code>
  -    property) accessible to the remainder of the current
  -    page.  No type conversion is performed on the returned property value,
  -    unless it is a Java primitive type, in which case it is wrapped in the
  -    appropriate wrapper class (i.e. int is wrapped by java.lang.Integer).</p>
  -
  -    <p>If you specify a "value" attribute, the exposed bean will be of type
  -    <code>java.lang.String</code> and initialized to the specified value.</p>
  -
  -    <p>If you specify a body, the exposed bean will be of type
  -    <code>java.lang.String</code> and initialized to the body content.</p>
  -
  -    <p>You can not specify a "value" attribute and body simultaneously - 
  -    JspException will be thrown.</p>
  +    <p>Create a new attribute (in the scope specified by the
  +    <code>toScope</code> property, if any), and a corresponding scripting
  +    variable, both of which are named by the value of the <code>id</code>
  +    attribute.  The corresponding value to which this new attribute (and
  +    scripting variable) is set are specified via use of exactly one of the
  +    following approaches (trying to use more than one will result in a
  +    JspException being thrown):</p>
  +    <ul>
  +    <li>Specify a <code>name</code> attribute (plus optional
  +        <code>property</code> and <code>scope</code> attributes) -
  +        The created attribute and scripting variable will be of the type of the
  +        retrieved JavaBean property, unless it is a Java primitive type,
  +        in which case it will be wrapped in the appropriate wrapper class
  +        (i.e. int is wrapped by java.lang.Integer).</li>
  +    <li>Specify a <code>value</code> attribute - The created attribute and
  +        scripting variable will be of type <code>java.lang.String</code>,
  +        set to the value of this attribute.</li>
  +    <li>Specify nested body content - The created attribute and scripting
  +        variable will be of type <code>java.lang.String</code>, set to
  +        the value of the nested body content.</li>
  +    </ul>
   
       <p>If a problem occurs while retrieving the specified bean property, a
       request time exception will be thrown.</p>
  @@ -188,7 +194,7 @@
         specified) or the attribute name of the bean that is duplicated with
         the new reference created by this tag (if <code>property</code> is not
         also specified).  This attribute is required unless you specify
  -      a <code>value</code> attribute.</p>
  +      a <code>value</code> attribute or nested body content.</p>
         </info>
       </attribute>
   
  @@ -246,7 +252,7 @@
         <info>
         <p>The <code>java.lang.String</code> value to which the exposed bean
         should be set.  This attribute is required unless you specify the
  -      <code>name</code> attribute.</p>
  +      <code>name</code> attribute or nested body content.</p>
         </info>
       </attribute>
   
  
  
  
  1.17      +59 -23    jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTag.java
  
  Index: DefineTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTag.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DefineTag.java	16 Mar 2002 05:04:33 -0000	1.16
  +++ DefineTag.java	23 Jun 2002 00:07:16 -0000	1.17
  @@ -91,6 +91,13 @@
           MessageResources.getMessageResources
           ("org.apache.struts.taglib.bean.LocalStrings");
   
  +
  +    /**
  +     * The body content of this tag (if any).
  +     */
  +    protected String body = null;
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -195,20 +202,38 @@
   
       // --------------------------------------------------------- Public Methods
   
  +
       /**
  -    *
  -    * Check if we need to evaluate the body of the tag
  -    *
  -    * @exception JspException if a JSP exception has occurred
  -    */
  +     * Check if we need to evaluate the body of the tag
  +     *
  +     * @exception JspException if a JSP exception has occurred
  +     */
       public int doStartTag() throws JspException {
          
  -        if( this.name!=null || this.value!=null )
  -            return (SKIP_BODY);
  -        else
  -            return (EVAL_BODY_TAG);
  +        return (EVAL_BODY_TAG);
  +
  +    }
  +
  +
  +    /**
  +     * Save the body content of this tag (if any), or throw a JspException
  +     * if the value was already defined.
  +     *
  +     * @exception JspException if value was defined by an attribute
  +     */
  +    public int doAfterBody() throws JspException {
  +
  +        if (bodyContent != null) {
  +            body = bodyContent.getString();
  +            if (body != null) {
  +                body = body.trim();
  +            }
  +        }
  +        return (SKIP_BODY);
  +
       }
   
  +
       /**
        * Retrieve the required property and expose it as a scripting variable.
        *
  @@ -216,21 +241,31 @@
        */
       public int doEndTag() throws JspException {
   
  -        if( ( this.value!=null || 
  -              this.name!=null ) && 
  -                bodyContent!=null )
  -                throw new JspException( messages.getMessage("define.value", name) );
  +        // Enforce restriction on ways to declare the new value
  +        int n = 0;
  +        if (this.body != null) {
  +            n++;
  +        }
  +        if (this.name != null) {
  +            n++;
  +        }
  +        if (this.value != null) {
  +            n++;
  +        }
  +        if (n != 1) {
  +            JspException e =
  +                new JspException(messages.getMessage("define.value"));
  +            RequestUtils.saveException(pageContext, e);
  +            throw e;
  +        }
   
           // Retrieve the required property value
           Object value = this.value;
  -        if ((value == null) && (name!=null)) {
  +        if ((value == null) && (name != null)) {
               value = RequestUtils.lookup(pageContext, name, property, scope);
           }
  -        if (value == null) {
  -            value = bodyContent.getString();
  -            if (value != null) {
  -                value = ((String) value).trim();
  -            }
  +        if ((value == null) && (body != null)) {
  +            value = body;
           }
           if (value == null) {
               JspException e =
  @@ -260,6 +295,7 @@
       public void release() {
   
           super.release();
  +        body = null;
           id = null;
           name = null;
           property = null;
  
  
  
  1.18      +1 -1      jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalStrings.properties,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- LocalStrings.properties	16 Mar 2002 05:04:33 -0000	1.17
  +++ LocalStrings.properties	23 Jun 2002 00:07:16 -0000	1.18
  @@ -1,6 +1,6 @@
   cookie.get=No cookie {0} was included in this request
   define.null=Define tag cannot set a null value
  -define.value=Define tag can contain value/name attributes or body.
  +define.value=Define tag can contain only one of name attribute, value attribute, or body content
   header.get=No header {0} was included in this request
   include.destination=You must specify exactly one of forward, href, or page
   include.forward=Missing ActionForward entry {0}
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>