craigmcc    01/01/26 12:12:38

  Modified:    src/doc  struts-bean.xml
               src/share/org/apache/struts/taglib/bean DefineTag.java
                        package.html
  Log:
  Add a new "toScope" attribute to the <bean:define> tag, so that you can
  declare which scope (page, request, session, or application) the new bean
  should be created in.  This lives up to the promise of the Bean Tag
  Developer's Guide, which says you can use the "scope" attribute for this.
  In reality, the "scope" attribute identifies the scope of the bean you are
  copying *from*.
  
  Submitted by: Dennis <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.17      +13 -1     jakarta-struts/src/doc/struts-bean.xml
  
  Index: struts-bean.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/doc/struts-bean.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- struts-bean.xml   2001/01/10 23:11:37     1.16
  +++ struts-bean.xml   2001/01/26 20:12:32     1.17
  @@ -103,7 +103,8 @@
       <bodycontent>empty</bodycontent>
       <info>
       <p>Retrieve the value of a specified bean property, and define it
  -    as a page scope attribute accessible to the remainder of the current
  +    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>
  @@ -183,6 +184,17 @@
         <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>
  +
  +    <attribute>
  +      <name>toScope</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +      <info>
  +      <p>Specifies the variable scope into which the newly defined bean will
  +      be created.  If not specified, the bean will be created in
  +      <code>page</code> scope.</p>
         </info>
       </attribute>
   
  
  
  
  1.9       +27 -5     
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefineTag.java    2001/01/07 22:39:07     1.8
  +++ DefineTag.java    2001/01/26 20:12:35     1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTag.java,v 1.8 
2001/01/07 22:39:07 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2001/01/07 22:39:07 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTag.java,v 1.9 
2001/01/26 20:12:35 craigmcc Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/01/26 20:12:35 $
    *
    * ====================================================================
    *
  @@ -79,7 +79,7 @@
    * bean property.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2001/01/07 22:39:07 $
  + * @version $Revision: 1.9 $ $Date: 2001/01/26 20:12:35 $
    */
   
   public class DefineTag extends TagSupport {
  @@ -154,6 +154,20 @@
   
   
       /**
  +     * The scope within which the newly defined bean will be creatd.
  +     */
  +    protected String toScope = null;
  +
  +    public String getToScope() {
  +        return (this.toScope);
  +    }
  +
  +    public void setToScope(String toScope) {
  +        this.toScope = toScope;
  +    }
  +
  +
  +    /**
        * The fully qualified Java class name of the value to be exposed.
        */
       protected String type = null;
  @@ -243,7 +257,14 @@
           }
   
           // Expose this value as a scripting variable
  -        pageContext.setAttribute(id, value);
  +        int inScope = PageContext.PAGE_SCOPE;
  +        if ("request".equals(toScope))
  +            inScope = PageContext.REQUEST_SCOPE;
  +        else if ("session".equals(toScope))
  +            inScope = PageContext.SESSION_SCOPE;
  +        else if ("application".equals(toScope))
  +            inScope = PageContext.APPLICATION_SCOPE;
  +        pageContext.setAttribute(id, value, inScope);
           return (SKIP_BODY);
   
       }
  @@ -259,6 +280,7 @@
           name = null;
           property = null;
           scope = null;
  +        toScope = "page";
           type = null;
   
       }
  
  
  
  1.2       +7 -4      
jakarta-struts/src/share/org/apache/struts/taglib/bean/package.html
  
  Index: package.html
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/package.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.html      2001/01/07 01:01:40     1.1
  +++ package.html      2001/01/26 20:12:36     1.2
  @@ -117,7 +117,7 @@
       getFoo().getBar().getBaz()
   </pre>
   <p>If a nested reference is used in a setter (such as when an input form is
  -processed), the property setter is called on the <strong>last</code> property
  +processed), the property setter is called on the <strong>last</strong> property
   in the chain.  For the above property reference, the equivalent Java
   expression would be:</p>
   <pre>
  @@ -293,7 +293,7 @@
   all the power of property references, as discused
   <a href="#doc.Properties.References">above</a>.  It can be used in a
   variety of different ways, described further below.  Unless you specify
  -the "scope" attribute, all defined beans will be created in page scope.</p>
  +the "toScope" attribute, all defined beans will be created in page scope.</p>
   
   <p><em>Introduce A String Constant</em> - You can create a new bean that has
   a constant String value (or the result of calculating a runtime expression):
  @@ -319,9 +319,12 @@
   <p><em>Copy An Existing Bean Property</em> - You can create a new bean that
   is initialized to the value returned by a property getter.  The value of the
   "property" attribute can be any simple, nested, or indexed property reference
  -that follows the rules described earlier.</p>
  +that follows the rules described earlier.  In the first example below, we
  +also illustrate accessing the property of a request scope bean, and creating
  +the new bean in session scope (rather than the default page scope).</p>
   <pre>
  -    &lt;bean:define id="foo" name="bar" property="baz"/&gt;
  +    &lt;bean:define id="foo" name="bar" property="baz" scope="request"
  +     toScope="session"/&gt;
       &lt;bean:define id="bop" name="user" property="role[3].name"/&gt;
   </pre>
   
  
  
  

Reply via email to