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...@locus.apache.org on 2000/12/07 02:19:13 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/bean WriteTag.java

craigmcc    00/12/06 17:19:12

  Modified:    src/doc  struts-bean.xml
               src/share/org/apache/struts/taglib/bean WriteTag.java
  Log:
  Add a new "ignore" attribute to the <bean:write> tag.  If you set this
  attribute to "true", attempts to write the content of a bean (specified
  by the "name" attribute) that is not found will simply return no output,
  rather than throwing an exception.  This is consistent with what happens
  when <bean:write> is asked to render a bean property whose value is null.
  
  The default behavior remains to throw an exception in this scenario, which
  is consistent with how missing beans are handled by all the other tags.
  
  Revision  Changes    Path
  1.8       +15 -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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- struts-bean.xml	2000/11/04 00:46:29	1.7
  +++ struts-bean.xml	2000/12/07 01:19:10	1.8
  @@ -621,6 +621,19 @@
       </attribute>
   
       <attribute>
  +      <name>ignore</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>If this attribute is set to <code>true</code>, and the bean specified
  +      by the <code>name</code> and <code>scope</code> attributes does not
  +      exist, simply return without writing anything.  The default value is
  +      <code>false</code>, which will cause a runtime exception to be thrown,
  +      consistent with the other tags in this tag library.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
         <name>name</name>
         <required>true</required>
         <rtexprvalue>true</rtexprvalue>
  @@ -640,7 +653,8 @@
         <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 bean
  -      identified by <code>name</code> will itself be rendered.</p>
  +      identified by <code>name</code> will itself be rendered.  If the
  +      specified property returns null, no output will be rendered.</p>
         </info>
       </attribute>
   
  
  
  
  1.7       +23 -5     jakarta-struts/src/share/org/apache/struts/taglib/bean/WriteTag.java
  
  Index: WriteTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/WriteTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WriteTag.java	2000/10/30 06:02:15	1.6
  +++ WriteTag.java	2000/12/07 01:19:11	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/WriteTag.java,v 1.6 2000/10/30 06:02:15 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/10/30 06:02:15 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/WriteTag.java,v 1.7 2000/12/07 01:19:11 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2000/12/07 01:19:11 $
    *
    * ====================================================================
    *
  @@ -81,7 +81,7 @@
    * output stream, optionally filtering characters that are sensitive in HTML.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2000/10/30 06:02:15 $
  + * @version $Revision: 1.7 $ $Date: 2000/12/07 01:19:11 $
    */
   
   public class WriteTag extends TagSupport {
  @@ -106,6 +106,21 @@
   
   
       /**
  +     * Should we ignore missing beans and simply output nothing?
  +     */
  +    protected boolean ignore = false;
  +
  +    public boolean getIgnore() {
  +        return (this.ignore);
  +    }
  +
  +    public void setIgnore(boolean ignore) {
  +        this.ignore = ignore;
  +    }
  +
  +
  +
  +    /**
        * The message resources for this package.
        */
       protected static MessageResources messages =
  @@ -180,7 +195,9 @@
                   throw new JspException
                       (messages.getMessage("getter.scope", scope));
               }
  -            if (bean == null) {
  +	    if ((bean == null) && ignore)
  +                return (SKIP_BODY);  // Nothing to output
  +            else if (bean == null) {
                   JspException e = new JspException
                       (messages.getMessage("getter.bean", name));
                   pageContext.setAttribute(Action.EXCEPTION_KEY, e,
  @@ -256,6 +273,7 @@
   
           super.release();
           filter = null;
  +	ignore = false;
   	name = null;
   	property = null;
   	scope = null;