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/06/13 04:05:20 UTC

cvs commit: jakarta-struts/web/documentation tags.html users_guide.html

craigmcc    00/06/12 19:05:18

  Modified:    src/conf struts.tld
               web/documentation tags.html users_guide.html
  Added:       src/share/org/apache/struts/taglib
                        IfParameterNotNullTag.java IfParameterNullTag.java
                        RedirectTag.java
  Log:
  Add the following new custom tags to the struts library:
  
  ifParameterNull - Conditionally evaluate the body of this tag
    if the specified request parameter is not present in this
    request, or it is present with a zero length (as would be
    returned by an input field the user forgot to fill in).
  
  ifParameterNotNull - Conditionally evaluate the body of this tag
    if the specified request parameter is present in this request,
    and the value has a length greater than zero.
  
  redirect - Issue a response.sendRedirect() to the specified URL,
    after automatically encoding it so that sessions still work
    in the absence of cookies (as the link tag does).  In addition,
    skips evaluating the rest of the current page so that the user
    does not have to remember to include a "return" statement to
    avoid problems.
  
  Revision  Changes    Path
  1.4       +36 -0     jakarta-struts/src/conf/struts.tld
  
  Index: struts.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/conf/struts.tld,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- struts.tld	2000/06/11 22:18:55	1.3
  +++ struts.tld	2000/06/13 02:05:14	1.4
  @@ -77,6 +77,42 @@
     </tag>
   
   
  +  <tag>
  +    <name>ifParameterNotNull</name>
  +    <tagclass>org.apache.struts.taglib.IfParameterNotNullTag</tagclass>
  +    <bodycontent>JSP</bodycontent>
  +    <attribute>
  +      <name>name</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
  +  <tag>
  +    <name>ifParameterNull</name>
  +    <tagclass>org.apache.struts.taglib.IfParameterNullTag</tagclass>
  +    <bodycontent>JSP</bodycontent>
  +    <attribute>
  +      <name>name</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
  +  <tag>
  +    <name>redirect</name>
  +    <tagclass>org.apache.struts.taglib.RedirectTag</tagclass>
  +    <bodycontent>empty</bodycontent>
  +    <attribute>
  +      <name>href</name>
  +      <required>true</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
     <!-- =================== Form Management Tags ===================== -->
   
   
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/taglib/IfParameterNotNullTag.java
  
  Index: IfParameterNotNullTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/IfParameterNotNullTag.java,v 1.1 2000/06/13 02:05:15 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/06/13 02:05:15 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.struts.taglib;
  
  
  import java.io.IOException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  
  /**
   * Conditionally include the body of this tag if the specified parameter
   * is present in the current request, and has a length greather than zero.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/06/13 02:05:15 $
   */
  
  public class IfParameterNotNullTag extends TagSupport {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The name of the parameter being compared.
       */
      protected String name = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the parameter name.
       */
      public String getName() {
  
  	return (this.name);
  
      }
  
  
      /**
       * Set the parameter name.
       *
       * @param name The new parameter name
       */
      public void setName(String name) {
  
  	this.name = name;
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Retrieve the specified parameter, and decide whether
       * or not to include the body content.
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
  
  	// Retrieve the value of the specified parameter
  	HttpServletRequest request =
  	  (HttpServletRequest) pageContext.getRequest();
  	String value = request.getParameter(name);
  
  	// Conditionally evaluate the body of our tag
  	if ((value != null) && (value.length() > 0))
  	    return (EVAL_BODY_INCLUDE);
  	else
  	    return (SKIP_BODY);
  
      }
  
  
  
  }
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/taglib/IfParameterNullTag.java
  
  Index: IfParameterNullTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/IfParameterNullTag.java,v 1.1 2000/06/13 02:05:15 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/06/13 02:05:15 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.struts.taglib;
  
  
  import java.io.IOException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  
  
  /**
   * Conditionally include the body of this tag if the specified parameter
   * is not present in the current request, or it is present as a zero length
   * string.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/06/13 02:05:15 $
   */
  
  public class IfParameterNullTag extends TagSupport {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The name of the parameter being compared.
       */
      protected String name = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the parameter name.
       */
      public String getName() {
  
  	return (this.name);
  
      }
  
  
      /**
       * Set the parameter name.
       *
       * @param name The new parameter name
       */
      public void setName(String name) {
  
  	this.name = name;
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Retrieve the specified parameter, and decide whether
       * or not to include the body content.
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
  
  	// Retrieve the value of the specified parameter
  	HttpServletRequest request =
  	  (HttpServletRequest) pageContext.getRequest();
  	String value = request.getParameter(name);
  
  	// Conditionally evaluate the body of our tag
  	if ((value == null) || (value.length() == 0))
  	    return (EVAL_BODY_INCLUDE);
  	else
  	    return (SKIP_BODY);
  
      }
  
  
  
  }
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/taglib/RedirectTag.java
  
  Index: RedirectTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/RedirectTag.java,v 1.1 2000/06/13 02:05:16 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/06/13 02:05:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.struts.taglib;
  
  
  import java.io.IOException;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.JspWriter;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.TagSupport;
  import org.apache.struts.util.BeanUtils;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * Perform a sendRedirect() to the specified URL, and skip evaluating
   * the remainder of the current page.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/06/13 02:05:16 $
   */
  
  public class RedirectTag extends TagSupport {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The hyperlink URI.
       */
      protected String href = null;
  
  
      /**
       * The message resources for this package.
       */
      protected static MessageResources messages =
  	MessageResources.getMessageResources
  	("org.apache.struts.taglib.LocalStrings");
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the hyperlink URI.
       */
      public String getHref() {
  
  	return (this.href);
  
      }
  
  
      /**
       * Set the hyperlink URI.
       *
       * @param href Set the hyperlink URI
       */
      public void setHref(String href) {
  
  	this.href = href;
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Render the beginning of the hyperlink.
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
  
  	// Perform the requested redirect
  	HttpServletResponse response =
  	  (HttpServletResponse) pageContext.getResponse();
  	try {
  	    response.sendRedirect(response.encodeRedirectURL(href));
  	} catch (IOException e) {
  	    throw new JspException
  		(messages.getMessage("baseFieldTag.io", e.toString()));
  	}
  
  	// Skip the remainder of the current page
  	return (SKIP_PAGE);
  
      }
  
  
  }
  
  
  
  1.3       +72 -0     jakarta-struts/web/documentation/tags.html
  
  Index: tags.html
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/documentation/tags.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- tags.html	2000/06/12 16:00:53	1.2
  +++ tags.html	2000/06/13 02:05:18	1.3
  @@ -361,6 +361,54 @@
   <a href="#Top">Top</a>
   
   
  +<a name="ifParameterNotNull"></a>
  +<h1><i>ifParameterNotNull</i> - Conditionally Evaluate Tag Body</h1>
  +
  +<p>Evaluates and processes the body of this tag if the specified parameter
  +was included in this request with a length greater than zero.</p>
  +
  +<table width="100%" border="1">
  +  <tr>
  +    <th width="15%">Attribute</th>
  +    <th width="85%">Description</th>
  +  </tr>
  +  <tr>
  +    <td align="center">name</td>
  +    <td>
  +      Name of the request parameter whose value must be
  +      present for conditional evaluation of the tag body
  +      to take place.
  +    </td>
  +  </tr>
  +</table>
  +
  +<a href="#Top">Top</a>
  +
  +
  +<a name="ifParameterNull"></a>
  +<h1><i>ifParameterNull</i> - Conditionally Evaluate Tag Body</h1>
  +
  +<p>Evaluates and processes the body of this tag if the specified parameter
  +was not included in this request, or is present with a length of zero.</p>
  +
  +<table width="100%" border="1">
  +  <tr>
  +    <th width="15%">Attribute</th>
  +    <th width="85%">Description</th>
  +  </tr>
  +  <tr>
  +    <td align="center">name</td>
  +    <td>
  +      Name of the request parameter whose value must not be
  +      present for conditional evaluation of the tag body
  +      to take place.
  +    </td>
  +  </tr>
  +</table>
  +
  +<a href="#Top">Top</a>
  +
  +
   <a name="link"></a>
   <h1><i>link</i> - Render HTML Hyperlink</h1>
   
  @@ -605,6 +653,30 @@
         Value that is matched against the underlying bean property value.
         If the property has the same value, this radio button will be
         rendered as <code>checked</code>.
  +    </td>
  +  </tr>
  +</table>
  +
  +<a href="#Top">Top</a>
  +
  +
  +<a name="redirect"></a>
  +<h1><i>link</i> - Render HTML Hyperlink</h1>
  +
  +<p>Perform a response.sendRedirect() call to the specified URL, and
  +skip evaluation of the remainder of this page.  URL rewriting will be
  +applied automatically to maintain session state in the absence of
  +cookies.</p>
  +
  +<table width="100%" border="1">
  +  <tr>
  +    <th width="15%">Attribute</th>
  +    <th width="85%">Description</th>
  +  </tr>
  +  <tr>
  +    <td align="center">href</td>
  +    <td>
  +      URL to which the user will be redirected.
       </td>
     </tr>
   </table>
  
  
  
  1.3       +8 -2      jakarta-struts/web/documentation/users_guide.html
  
  Index: users_guide.html
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/documentation/users_guide.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- users_guide.html	2000/06/05 05:28:50	1.2
  +++ users_guide.html	2000/06/13 02:05:18	1.3
  @@ -6,7 +6,7 @@
   
   <div align="center">
   <h1>Struts User's Guide</h2>
  -<h3>$Id: users_guide.html,v 1.2 2000/06/05 05:28:50 craigmcc Exp $</h3>
  +<h3>$Id: users_guide.html,v 1.3 2000/06/13 02:05:18 craigmcc Exp $</h3>
   </div>
   
   
  @@ -634,7 +634,13 @@
       value.</li>
   <li><a href="tags.html#ifParameterNotEquals">ifParameterNotEquals</a>
       evaluates its tag body only if a specified request parameter does not
  -    have a specified value.</li>
  +    have a specified value, or is not present.</li>
  +<li><a href="tags.html#ifParameterNotNull">ifParameterNotNull</a>
  +    evaluates its tag body only if a specified request parameter is included
  +    in this request, and has a length greater than zero.</li>
  +<li><a href="tags.html#ifParameterNull">ifParameterNull</a> evaluates its
  +    tag body only if a specified request parameter is not included in this
  +    request, or if it is included with zero length.</li>
   <li><a href="tags.html#link">link</a> generates a hyperlink, and automatically
       applies URL encoding to maintain session state in the absence of
       cookie support.</li>