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/16 03:32:27 UTC

cvs commit: jakarta-struts/web/example/WEB-INF action.xml

craigmcc    00/06/15 18:32:26

  Modified:    src/conf struts.tld
               src/example/org/apache/struts/example
                        EditRegistrationAction.java
                        EditSubscriptionAction.java LogonAction.java
                        LogonForm.java RegistrationForm.java
                        SaveRegistrationAction.java
                        SaveSubscriptionAction.java SubscriptionForm.java
               src/share/org/apache/struts/action ActionMapping.java
                        ActionMappingBase.java ActionServlet.java
               web/example index.jsp mainMenu.jsp registration.jsp
                        subscription.jsp
               web/example/WEB-INF action.xml
  Added:       src/share/org/apache/struts/action ValidatingActionForm.java
               src/share/org/apache/struts/taglib IfPropertyEqualsTag.java
                        IfPropertyNotEqualsTag.java
  Log:
  Add the ValidatingActionForm support contributed by Jeff Hutchison.  This
  also necessitated some changes in the logic of the example application
  (which was using query string parameters to identify which maintenance
  action to perform).
  
  Added two new custom tags:
  
    <struts:ifPropertyEquals name="beanName" property="propertyName"
                             scope="scopeValue" value="valueToCompare" />
  
    <struts:ifPropertyNotEquals name="beanName" property="propertyName"
                                scope="scopeValue" value="valueToCompare" />
  
  for conditional generation depending on the value of an arbitrary property
  of an arbitrary attribute.  These tags illustrate the clash we have over
  the attribute name "name", which should (for consistency) refer to attributes,
  not properties.  Those changes will occur later.
  
  Revision  Changes    Path
  1.8       +54 -0     jakarta-struts/src/conf/struts.tld
  
  Index: struts.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/conf/struts.tld,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- struts.tld	2000/06/15 18:15:16	1.7
  +++ struts.tld	2000/06/16 01:32:21	1.8
  @@ -136,6 +136,60 @@
   
   
     <tag>
  +    <name>ifPropertyEquals</name>
  +    <tagclass>org.apache.struts.taglib.IfPropertyEqualsTag</tagclass>
  +    <bodycontent>JSP</bodycontent>
  +    <attribute>
  +      <name>name</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>property</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>scope</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>value</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
  +  <tag>
  +    <name>ifPropertyNotEquals</name>
  +    <tagclass>org.apache.struts.taglib.IfPropertyNotEqualsTag</tagclass>
  +    <bodycontent>JSP</bodycontent>
  +    <attribute>
  +      <name>name</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>property</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>scope</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>value</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +
  +  <tag>
       <name>redirect</name>
       <tagclass>org.apache.struts.taglib.RedirectTag</tagclass>
       <bodycontent>empty</bodycontent>
  
  
  
  1.2       +28 -19    jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java
  
  Index: EditRegistrationAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EditRegistrationAction.java	2000/05/31 22:28:14	1.1
  +++ EditRegistrationAction.java	2000/06/16 01:32:21	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java,v 1.1 2000/05/31 22:28:14 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:14 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditRegistrationAction.java,v 1.2 2000/06/16 01:32:21 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:21 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    * User (if any).
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:14 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:21 $
    */
   
   public final class EditRegistrationAction extends ActionBase {
  @@ -118,18 +118,24 @@
   	Locale locale = getLocale(request);
   	MessageResources messages = getResources(servlet);
   	HttpSession session = request.getSession();
  +	String action = request.getParameter("action");
  +	if (action == null)
  +	    action = "Create";
   
   	// Is there a currently logged on user?
  -	User user = (User) session.getAttribute(Constants.USER_KEY);
  -	if (user == null) {
  -	    if (servlet.getDebug() >= 1)
  -	        servlet.log("EditRegistrationAction: User is not logged on in session "
  -	                    + session.getId());
  -	    String uri = Constants.LOGON_PAGE;
  -	    RequestDispatcher rd =
  -	      servlet.getServletContext().getRequestDispatcher(uri);
  -	    rd.forward(request, response);
  -	    return;
  +	User user = null;
  +	if (!"Create".equals(action)) {
  +	    user = (User) session.getAttribute(Constants.USER_KEY);
  +	    if (user == null) {
  +		if (servlet.getDebug() >= 1)
  +		    servlet.log("EditRegistrationAction: User is not logged on in session "
  +	                        + session.getId());
  +	        String uri = Constants.LOGON_PAGE;
  +	        RequestDispatcher rd =
  +	          servlet.getServletContext().getRequestDispatcher(uri);
  +	        rd.forward(request, response);
  +	        return;
  +	    }
   	}
   
   	// Populate the user registration form
  @@ -138,12 +144,15 @@
   	    session.setAttribute(mapping.getFormAttribute(), form);
   	}
   	RegistrationForm regform = (RegistrationForm) form;
  -	regform.setUsername(user.getUsername());
  -	regform.setPassword(null);
  -	regform.setPassword2(null);
  -	regform.setFullName(user.getFullName());
  -	regform.setFromAddress(user.getFromAddress());
  -	regform.setReplyToAddress(user.getReplyToAddress());
  +	regform.setAction(action);
  +	if (user != null) {
  +	    regform.setUsername(user.getUsername());
  +	    regform.setPassword(null);
  +	    regform.setPassword2(null);
  +	    regform.setFullName(user.getFullName());
  +	    regform.setFromAddress(user.getFromAddress());
  +	    regform.setReplyToAddress(user.getReplyToAddress());
  +	}
   
   	// Forward control to the edit user registration page
   	String uri = ((ApplicationMapping) mapping).getSuccess();
  
  
  
  1.2       +4 -3      jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java
  
  Index: EditSubscriptionAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EditSubscriptionAction.java	2000/05/31 22:28:14	1.1
  +++ EditSubscriptionAction.java	2000/06/16 01:32:21	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java,v 1.1 2000/05/31 22:28:14 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:14 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/EditSubscriptionAction.java,v 1.2 2000/06/16 01:32:21 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:21 $
    *
    * ====================================================================
    *
  @@ -83,7 +83,7 @@
    * <code>SubscriptionForm</code> from the currently specified subscription.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:14 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:21 $
    */
   
   public final class EditSubscriptionAction extends ActionBase {
  @@ -161,6 +161,7 @@
   	    session.setAttribute(mapping.getFormAttribute(), form);
   	}
   	SubscriptionForm subform = (SubscriptionForm) form;
  +	subform.setAction(action);
   	subform.setHost(subscription.getHost());
   	subform.setUsername(subscription.getUsername());
   	subform.setPassword(subscription.getPassword());
  
  
  
  1.3       +5 -10     jakarta-struts/src/example/org/apache/struts/example/LogonAction.java
  
  Index: LogonAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LogonAction.java	2000/06/15 18:00:01	1.2
  +++ LogonAction.java	2000/06/16 01:32:21	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonAction.java,v 1.2 2000/06/15 18:00:01 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/06/15 18:00:01 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonAction.java,v 1.3 2000/06/16 01:32:21 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/06/16 01:32:21 $
    *
    * ====================================================================
    *
  @@ -83,7 +83,7 @@
    * Implementation of <strong>Action</strong> that validates a user logon.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/06/15 18:00:01 $
  + * @version $Revision: 1.3 $ $Date: 2000/06/16 01:32:21 $
    */
   
   public final class LogonAction extends ActionBase {
  @@ -119,14 +119,9 @@
   	User user = null;
   
   	// Validate the request parameters specified by the user
  -	String value = null;
   	Vector errors = new Vector();
   	String username = ((LogonForm) form).getUsername();
  -	if ((username == null) || (username.length() < 1))
  -	    errors.addElement("error.username.required");
   	String password = ((LogonForm) form).getPassword();
  -	if ((password == null) || (password.length() < 1))
  -	    errors.addElement("error.password.required");
   	Hashtable database = (Hashtable)
   	  servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
   	if (database == null)
  @@ -142,7 +137,7 @@
   	// Report any errors we have discovered back to the original form
   	if (errors.size() > 0) {
   	    saveErrors(request, errors);
  -	    String uri = ((ApplicationMapping) mapping).getFailure();
  +	    String uri = mapping.getInputForm();
   	    RequestDispatcher rd =
   	      servlet.getServletContext().getRequestDispatcher(uri);
   	    rd.forward(request, response);
  
  
  
  1.2       +32 -5     jakarta-struts/src/example/org/apache/struts/example/LogonForm.java
  
  Index: LogonForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonForm.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogonForm.java	2000/05/31 22:28:14	1.1
  +++ LogonForm.java	2000/06/16 01:32:21	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonForm.java,v 1.1 2000/05/31 22:28:14 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:14 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/LogonForm.java,v 1.2 2000/06/16 01:32:21 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:21 $
    *
    * ====================================================================
    *
  @@ -63,7 +63,8 @@
   package org.apache.struts.example;
   
   
  -import org.apache.struts.action.ActionForm;
  +import java.util.Vector;
  +import org.apache.struts.action.ValidatingActionForm;
   
   
   /**
  @@ -75,10 +76,10 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:14 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:21 $
    */
   
  -public final class LogonForm implements ActionForm {
  +public final class LogonForm implements ValidatingActionForm {
   
   
       // --------------------------------------------------- Instance Variables
  @@ -145,6 +146,32 @@
   	    this.username = "";
   	else
   	    this.username = username;
  +
  +    }
  +
  +
  +    // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Validate the properties of this form bean, and return an array of
  +     * message keys for any errors we encounter.
  +     */
  +    public String[] validate() {
  +
  +        Vector errors = new Vector();
  +	if ((username == null) || (username.length() < 1))
  +	    errors.addElement("error.username.required");
  +	if ((password == null) || (password.length() < 1))
  +	    errors.addElement("error.password.required");
  +
  +        String[] results = null;
  +        if (errors.size() > 0) {
  +            results = new String[errors.size()];
  +            for (int i = 0; i < results.length; i++)
  +                results[i] = (String) errors.elementAt(i);
  +        }
  +        return results;
   
       }
   
  
  
  
  1.2       +114 -5    jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java
  
  Index: RegistrationForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RegistrationForm.java	2000/05/31 22:28:14	1.1
  +++ RegistrationForm.java	2000/06/16 01:32:21	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java,v 1.1 2000/05/31 22:28:14 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:14 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/RegistrationForm.java,v 1.2 2000/06/16 01:32:21 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:21 $
    *
    * ====================================================================
    *
  @@ -63,13 +63,16 @@
   package org.apache.struts.example;
   
   
  -import org.apache.struts.action.ActionForm;
  +import java.util.Vector;
  +import org.apache.struts.action.ValidatingActionForm;
   
   
   /**
    * Form bean for the user registration page.  This form has the following fields,
    * with default values in square brackets:
    * <ul>
  + * <li><b>action</b> - The maintenance action we are performing (Create, Delete,
  + *     or Edit).
    * <li><b>fromAddress</b> - The EMAIL address of the sender, to be included
    *     on sent messages.  [REQUIRED]
    * <li><b>fullName</b> - The full name of the sender, to be included on
  @@ -79,21 +82,28 @@
    *     when changing or setting.
    * <li><b>replyToAddress</b> - The "Reply-To" address to be included on
    *     sent messages.  [Same as from address]
  + * <li><b>submit</b> - The submit button that was pressed.
    * <li><b>username</b> - The registered username, which must be unique.
    *     [REQUIRED]
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:14 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:21 $
    */
   
  -public final class RegistrationForm implements ActionForm  {
  +public final class RegistrationForm implements ValidatingActionForm  {
   
   
       // --------------------------------------------------- Instance Variables
   
   
       /**
  +     * The maintenance action we are performing (Create or Edit).
  +     */
  +    private String action = "Create";
  +
  +
  +    /**
        * The from address.
        */
       private String fromAddress = "";
  @@ -125,6 +135,12 @@
   
   
       /**
  +     * The submit button that was pressed.
  +     */
  +    private String submit = "";
  +
  +
  +    /**
        * The username.
        */
       private String username = "";
  @@ -134,6 +150,31 @@
   
   
       /**
  +     * Return the maintenance action.
  +     */
  +    public String getAction() {
  +
  +	return (this.action);
  +
  +    }
  +
  +
  +    /**
  +     * Set the maintenance action.
  +     *
  +     * @param action The new maintenance action.
  +     */
  +    public void setAction(String action) {
  +
  +	if (action == null)
  +	    this.action = "";
  +	else
  +	    this.action = action;
  +
  +    }
  +
  +
  +    /**
        * Return the from address.
        */
       public String getFromAddress() {
  @@ -259,6 +300,31 @@
   
   
       /**
  +     * Return the submit button that was pressed.
  +     */
  +    public String getSubmit() {
  +
  +	return (this.submit);
  +
  +    }
  +
  +
  +    /**
  +     * Set the submit button that was pressed.
  +     *
  +     * @param submit The new submit button
  +     */
  +    public void setSubmit(String submit) {
  +
  +	if (submit == null)
  +	    this.submit = "";
  +	else
  +	    this.submit = submit;
  +
  +    }
  +
  +
  +    /**
        * Return the username.
        */
       public String getUsername() {
  @@ -279,6 +345,49 @@
   	    this.username = "";
   	else
   	    this.username = username;
  +
  +    }
  +
  +
  +    // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Validate the properties of this form bean, and return an array of
  +     * message keys for any errors we encounter.
  +     */
  +    public String[] validate() {
  +
  +	if ("Cancel".equals(submit))
  +	    return (null);
  +
  +        Vector errors = new Vector();
  +	if ((username == null) || (username.length() < 1))
  +	    errors.addElement("error.username.required");
  +	if (!password.equals(password))
  +	    errors.addElement("error.password.match");
  +	if ((fromAddress == null) || (fromAddress.length() < 1))
  +	    errors.addElement("error.fromAddress.required");
  +	else {
  +	    int atSign = fromAddress.indexOf("@");
  +	    if ((atSign < 1) || (atSign >= (fromAddress.length() - 1)))
  +		errors.addElement("error.fromAddress.format");
  +	}
  +	if ((fullName == null) || (fullName.length() < 1))
  +	    errors.addElement("error.fullName.required");
  +	if ((replyToAddress != null) && (replyToAddress.length() > 0)) {
  +	    int atSign = replyToAddress.indexOf("@");
  +	    if ((atSign < 1) || (atSign >= (replyToAddress.length() - 1)))
  +		errors.addElement("error.replyToAddress.format");
  +	}
  +
  +        String[] results = null;
  +        if (errors.size() > 0) {
  +            results = new String[errors.size()];
  +            for (int i = 0; i < results.length; i++)
  +                results[i] = (String) errors.elementAt(i);
  +        }
  +        return results;
   
       }
   
  
  
  
  1.3       +9 -26     jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java
  
  Index: SaveRegistrationAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SaveRegistrationAction.java	2000/06/15 18:00:01	1.2
  +++ SaveRegistrationAction.java	2000/06/16 01:32:22	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java,v 1.2 2000/06/15 18:00:01 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/06/15 18:00:01 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveRegistrationAction.java,v 1.3 2000/06/16 01:32:22 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/06/16 01:32:22 $
    *
    * ====================================================================
    *
  @@ -85,7 +85,7 @@
    * created, the user is also implicitly logged on.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/06/15 18:00:01 $
  + * @version $Revision: 1.3 $ $Date: 2000/06/16 01:32:22 $
    */
   
   public final class SaveRegistrationAction extends ActionBase {
  @@ -121,6 +121,8 @@
   	HttpSession session = request.getSession();
   	RegistrationForm regform = (RegistrationForm) form;
   	String action = request.getParameter("action");
  +	if (action == null)
  +	    action = "Create";
   	Hashtable database = (Hashtable)
   	  servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
   
  @@ -152,12 +154,12 @@
   	    return;
   	}
   
  +	// All required validations were done in the form bean
  +
   	// Validate the request parameters specified by the user
   	String value = null;
   	Vector errors = new Vector();
   	value = regform.getUsername();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.username.required");
   	if (("Create".equals(action)) &&
   	    (database.get(value) != null))
   	    errors.addElement("error.username.unique");
  @@ -169,30 +171,11 @@
   	    if ((value == null) || (value.length() < 1))
   		errors.addElement("error.password2.required");
   	}
  -	if (!regform.getPassword().equals(regform.getPassword2()))
  -	    errors.addElement("error.password.match");
  -	value = regform.getFromAddress();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.fromAddress.required");
  -	else {
  -	    int atSign = value.indexOf("@");
  -	    if ((atSign < 1) || (atSign >= (value.length() - 1)))
  -		errors.addElement("error.fromAddress.format");
  -	}
  -	value = regform.getFullName();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.fullName.required");
  -	value = regform.getReplyToAddress();
  -	if ((value != null) && (value.length() > 0)) {
  -	    int atSign = value.indexOf("@");
  -	    if ((atSign < 1) || (atSign >= (value.length() - 1)))
  -		errors.addElement("error.replyToAddress.format");
  -	}
   
   	// Report any errors we have discovered back to the original form
   	if (errors.size() > 0) {
   	    saveErrors(request, errors);
  -	    String uri = ((ApplicationMapping) mapping).getFailure();
  +	    String uri = mapping.getInputForm();
   	    RequestDispatcher rd =
   	      servlet.getServletContext().getRequestDispatcher(uri);
   	    rd.forward(request, response);
  
  
  
  1.3       +5 -31     jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java
  
  Index: SaveSubscriptionAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SaveSubscriptionAction.java	2000/06/15 18:00:02	1.2
  +++ SaveSubscriptionAction.java	2000/06/16 01:32:22	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java,v 1.2 2000/06/15 18:00:02 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/06/15 18:00:02 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SaveSubscriptionAction.java,v 1.3 2000/06/16 01:32:22 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/06/16 01:32:22 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    * the mail subscription entered by the user.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/06/15 18:00:02 $
  + * @version $Revision: 1.3 $ $Date: 2000/06/16 01:32:22 $
    */
   
   public final class SaveSubscriptionAction extends ActionBase {
  @@ -181,33 +181,7 @@
   	    return;
   	}
   
  -	// Validate the request parameters specified by the user
  -	String value = null;
  -	Vector errors = new Vector();
  -	value = subform.getHost();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.host.required");
  -	value = subform.getUsername();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.username.required");
  -	value = subform.getPassword();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.password.required");
  -	value = subform.getType();
  -	if ((value == null) || (value.length() < 1))
  -	    errors.addElement("error.type.required");
  -	else if (!"imap".equals(value) && !"pop3".equals(value))
  -	    errors.addElement("error.type.invalid");
  -
  -	// Report any errors we have discovered back to the original form
  -	if (errors.size() > 0) {
  -	    saveErrors(request, errors);
  -	    String uri = ((ApplicationMapping) mapping).getFailure();
  -	    RequestDispatcher rd =
  -	      servlet.getServletContext().getRequestDispatcher(uri);
  -	    rd.forward(request, response);
  -	    return;
  -	}
  +	// All required validations were done by the form itself
   
   	// Update the persistent subscription information
   	if (subform.getHost().length() > 0)
  
  
  
  1.2       +106 -5    jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java
  
  Index: SubscriptionForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SubscriptionForm.java	2000/05/31 22:28:14	1.1
  +++ SubscriptionForm.java	2000/06/16 01:32:22	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java,v 1.1 2000/05/31 22:28:14 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:14 $
  + * $Header: /home/cvs/jakarta-struts/src/example/org/apache/struts/example/SubscriptionForm.java,v 1.2 2000/06/16 01:32:22 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:22 $
    *
    * ====================================================================
    *
  @@ -63,31 +63,41 @@
   package org.apache.struts.example;
   
   
  -import org.apache.struts.action.ActionForm;
  +import java.util.Vector;
  +import org.apache.struts.action.ValidatingActionForm;
   
   
   /**
    * Form bean for the user profile page.  This form has the following fields,
    * with default values in square brackets:
    * <ul>
  + * <li><b>action</b> - The maintenance action we are performing (Create, Delete,
  + *     or Edit).
    * <li><b>host</b> - The mail host for this subscription.  [REQUIRED]
    * <li><b>password</b> - The password for this subscription.  [REQUIRED]
  + * <li><b>submit</b> - The submit button that was pressed.
    * <li><b>type</b> - The subscription type (imap,pop3)
          for this subscription.  [REQUIRED]
    * <li><b>username</b> - The username of this subscription.  [REQUIRED]
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:14 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:22 $
    */
   
  -public final class SubscriptionForm implements ActionForm  {
  +public final class SubscriptionForm implements ValidatingActionForm  {
   
   
       // --------------------------------------------------- Instance Variables
   
   
       /**
  +     * The maintenance action we are performing (Create or Edit).
  +     */
  +    private String action = "Create";
  +
  +
  +    /**
        * The host name.
        */
       private String host = "";
  @@ -100,6 +110,12 @@
   
   
       /**
  +     * The submit button that was pressed.
  +     */
  +    private String submit = "";
  +
  +
  +    /**
        * The subscription type.
        */
       private String type = "";
  @@ -115,6 +131,31 @@
   
   
       /**
  +     * Return the maintenance action.
  +     */
  +    public String getAction() {
  +
  +	return (this.action);
  +
  +    }
  +
  +
  +    /**
  +     * Set the maintenance action.
  +     *
  +     * @param action The new maintenance action.
  +     */
  +    public void setAction(String action) {
  +
  +	if (action == null)
  +	    this.action = "";
  +	else
  +	    this.action = action;
  +
  +    }
  +
  +
  +    /**
        * Return the host name.
        */
       public String getHost() {
  @@ -165,6 +206,31 @@
   
   
       /**
  +     * Return the submit button that was pressed.
  +     */
  +    public String getSubmit() {
  +
  +	return (this.submit);
  +
  +    }
  +
  +
  +    /**
  +     * Set the submit button that was pressed.
  +     *
  +     * @param submit The new submit button
  +     */
  +    public void setSubmit(String submit) {
  +
  +	if (submit == null)
  +	    this.submit = "";
  +	else
  +	    this.submit = submit;
  +
  +    }
  +
  +
  +    /**
        * Return the subscription type.
        */
       public String getType() {
  @@ -210,6 +276,41 @@
   	    this.username = "";
   	else
   	    this.username = username;
  +
  +    }
  +
  +
  +    // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Validate the properties of this form bean, and return an array of
  +     * message keys for any errors we encounter.
  +     */
  +    public String[] validate() {
  +
  +	if ("Cancel".equals(submit))
  +	    return (null);
  +
  +        Vector errors = new Vector();
  +	if ((host == null) || (host.length() < 1))
  +	    errors.addElement("error.host.required");
  +	if ((username == null) || (username.length() < 1))
  +	    errors.addElement("error.username.required");
  +	if ((password == null) || (password.length() < 1))
  +	    errors.addElement("error.password.required");
  +	if ((type == null) || (type.length() < 1))
  +	    errors.addElement("error.type.required");
  +	else if (!"imap".equals(type) && !"pop3".equals(type))
  +	    errors.addElement("error.type.invalid");
  +
  +        String[] results = null;
  +        if (errors.size() > 0) {
  +            results = new String[errors.size()];
  +            for (int i = 0; i < results.length; i++)
  +                results[i] = (String) errors.elementAt(i);
  +        }
  +        return results;
   
       }
   
  
  
  
  1.2       +24 -10    jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java
  
  Index: ActionMapping.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionMapping.java	2000/05/31 22:28:11	1.1
  +++ ActionMapping.java	2000/06/16 01:32:23	1.2
  @@ -1,13 +1,13 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v 1.1 2000/05/31 22:28:11 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:11 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v 1.2 2000/06/16 01:32:23 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:23 $
    *
    * ====================================================================
  - * 
  + *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    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
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    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 
  + *    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"
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - */ 
  + */
   
   
   package org.apache.struts.action;
  @@ -97,7 +97,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:11 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:23 $
    */
   
   public interface ActionMapping {
  @@ -174,6 +174,20 @@
        * @param formSuffix The new form suffix
        */
       public void setFormSuffix(String formSuffix);
  +
  +
  +    /**
  +     * Return the input form URI for this mapping.
  +     */
  +    public String getInputForm();
  +
  +
  +    /**
  +     * Set the input form URI for this mapping.
  +     *
  +     * @param inputForm The new input form URI
  +     */
  +    public void setInputForm(String inputForm);
   
   
       /**
  
  
  
  1.2       +31 -3     jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java
  
  Index: ActionMappingBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionMappingBase.java	2000/05/31 22:28:11	1.1
  +++ ActionMappingBase.java	2000/06/16 01:32:23	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java,v 1.1 2000/05/31 22:28:11 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 22:28:11 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java,v 1.2 2000/06/16 01:32:23 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 01:32:23 $
    *
    * ====================================================================
    *
  @@ -69,7 +69,7 @@
    * subclassing this class and adding new "getter" and "setter" methods.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 22:28:11 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/16 01:32:23 $
    */
   
   public class ActionMappingBase implements ActionMapping {
  @@ -126,6 +126,12 @@
   
   
       /**
  +     * The input form URI for this mapping.
  +     */
  +    protected String inputForm = null;
  +
  +
  +    /**
        * The request URI path used to select this particular mapping.
        */
       protected String path = null;
  @@ -241,6 +247,28 @@
       public void setFormSuffix(String formSuffix) {
   
   	this.formSuffix = formSuffix;
  +
  +    }
  +
  +
  +    /**
  +     * Return the input form URI for this mapping.
  +     */
  +    public String getInputForm() {
  +
  +	return (this.inputForm);
  +
  +    }
  +
  +
  +    /**
  +     * Set the input form URI for this mapping.
  +     *
  +     * @param inputForm The new input form URI
  +     */
  +    public void setInputForm(String inputForm) {
  +
  +	this.inputForm = inputForm;
   
       }
   
  
  
  
  1.7       +62 -19    jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ActionServlet.java	2000/06/15 19:39:01	1.6
  +++ ActionServlet.java	2000/06/16 01:32:23	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.6 2000/06/15 19:39:01 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/06/15 19:39:01 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.7 2000/06/16 01:32:23 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2000/06/16 01:32:23 $
    *
    * ====================================================================
    *
  @@ -63,27 +63,21 @@
   package org.apache.struts.action;
   
   
  -import java.util.Hashtable;
  -import java.util.MissingResourceException;
   import java.io.InputStream;
   import java.io.IOException;
  +import java.util.Hashtable;
  +import java.util.Locale;
  +import java.util.MissingResourceException;
  +import javax.servlet.RequestDispatcher;
   import javax.servlet.ServletException;
   import javax.servlet.UnavailableException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
  -import javax.xml.parsers.DocumentBuilder;
  -import javax.xml.parsers.DocumentBuilderFactory;
  -import javax.xml.parsers.ParserConfigurationException;
   import org.apache.struts.digester.Digester;
   import org.apache.struts.util.BeanUtils;
   import org.apache.struts.util.MessageResources;
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.NamedNodeMap;
  -import org.w3c.dom.Node;
  -import org.w3c.dom.NodeList;
   import org.xml.sax.SAXException;
   
   
  @@ -93,7 +87,7 @@
    * commonly known as "Model 2".  This nomenclature originated with a
    * description in the JavaServerPages Specification, version 0.92, and has
    * persisted ever since (in the absence of a better name).</p>
  - * 
  + *
    * <p>Generally, a "Model 2" application is architected as follows:</p>
    * <ul>
    * <li>The user interface will generally be created with JSP pages, which
  @@ -157,7 +151,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2000/06/15 19:39:01 $
  + * @version $Revision: 1.7 $ $Date: 2000/06/16 01:32:23 $
    */
   
   public class ActionServlet
  @@ -521,7 +515,9 @@
   	}
   
   	// Process any ActionForm bean related to this request
  -	ActionForm formInstance = processActionForm(request, mapping);
  +	ActionForm formInstance = processActionForm(mapping, request);
  +	if (!processValidate(mapping, formInstance, request, response))
  +	    return;
   
   	// Call the action instance itself
   	processActionInstance(mapping, formInstance, request, response);
  @@ -534,13 +530,13 @@
        * mapping, if any.  Return the <code>ActionForm</code> instance if
        * we created or utilized one.
        *
  -     * @param request The servlet request we are processing
        * @param mapping The ActionMapping we are processing
  +     * @param request The servlet request we are processing
        *
        * @exception ServletException if thrown by BeanUtils.populate()
        */
  -    protected ActionForm processActionForm(HttpServletRequest request,
  -					   ActionMapping mapping)
  +    protected ActionForm processActionForm(ActionMapping mapping,
  +    					   HttpServletRequest request)
   	throws ServletException {
   
   	HttpSession session = null;
  @@ -637,6 +633,53 @@
   	if ((period >= 0) && (period > slash))	// Strip the extenson (if any)
   	    path = path.substring(0, period);
   	return (path);
  +
  +    }
  +
  +
  +    /**
  +     * If this form is a ValidatingActionForm, perform the required validation
  +     * and forward back to the input form if there are any errors.  Return
  +     * <code>true</code> if we should continue processing (and call the Action
  +     * class perform() method), or <code>false</code> if have already forwarded
  +     * control back to the input form.
  +     *
  +     * @param mapping The ActionMapping we are processing
  +     * @param formInstance The ActionForm we are processing
  +     * @param request The servlet request we are processing
  +     * @param response The servlet response we are processing
  +     *
  +     * @exception IOException if an input/output error occurs
  +     * @exception ServletException if a servlet exception occurs
  +     */
  +    protected boolean processValidate(ActionMapping mapping,
  +        ActionForm formInstance, HttpServletRequest request,
  +        HttpServletResponse response)
  +        throws IOException, ServletException {
  +
  +	// Skip validation if it is not appropriate
  +	if (formInstance == null)
  +	    return (true);
  +	if (!(formInstance instanceof ValidatingActionForm))
  +	    return (true);
  +	if (mapping.getInputForm() == null)
  +	    return (true);
  +
  +	// Perform the requested validation
  +	if (debug >= 1)
  +	    log(" Validating bean properties");
  +	String errors[] = ((ValidatingActionForm) formInstance).validate();
  +	if ((errors == null) || (errors.length == 0))
  +	    return (true);
  +
  +	// Save our error messages and return to the input form
  +	String uri = mapping.getInputForm();
  +	if (debug >= 1)
  +	    log(" Form validation error: redirecting to: " + uri);
  +	request.setAttribute(Action.ERROR_KEY, errors);
  +	RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
  +	rd.forward(request, response);
  +	return (false);
   
       }
   
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/action/ValidatingActionForm.java
  
  Index: ValidatingActionForm.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ValidatingActionForm.java,v 1.1 2000/06/16 01:32:24 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/06/16 01:32:24 $
   *
   * ====================================================================
   *
   * 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.action;
  
  
  /**
   * An <strong>ValidatingActionForm</strong> is a JavaBean optionally associated with
   * a particular <code>ActionMapping</code>.  Such a bean will have had its
   * properties initialized from the corresponding request parameters before
   * the action's <code>perform()</code> method is called.
   *
   * @author Jeff Hutchison
   * @version $Revision: 1.1 $ $Date: 2000/06/16 01:32:24 $
   */
  
  public interface ValidatingActionForm extends ActionForm {
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Perform validations on the form input values included in this form bean.
       * If validation errors occur, return a String array containing the message
       * keys of corresponding error messages (in our application MessageResources)
       * to be displayed.  If no validation errors occur, return <code>null</code>.
       */
  
      public String[] validate();
  
  
  }
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/taglib/IfPropertyEqualsTag.java
  
  Index: IfPropertyEqualsTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/IfPropertyEqualsTag.java,v 1.1 2000/06/16 01:32:24 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/06/16 01:32:24 $
   *
   * ====================================================================
   *
   * 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 java.lang.reflect.Method;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import org.apache.struts.util.BeanUtils;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * Conditionally include the body of this tag if the specified property
   * of the specified attribute (in any scope) has the specified value.
   *
   * @author Arun M. Thomas <ar...@ipin.com>
   * @version $Revision: 1.1 $ $Date: 2000/06/16 01:32:24 $
   */
  
  public class IfPropertyEqualsTag extends BaseAttributeTag {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The message resources for this package.
       */
      private static MessageResources messages =
  	MessageResources.getMessageResources
  	("org.apache.struts.taglib.LocalStrings");
  
  
      /**
       * The name of the property to get.
       */
      private String property = null;
  
  
      /**
       * The value to compare to.
       */
      private String value = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the property name.
       */
      public String getProperty() {
  
  	return (this.property);
  
      }
  
  
      /**
       * Set the property name.
       *
       * @param property The property name
       */
      public void setProperty(String property) {
  
  	this.property = property;
  
      }
  
  
      /**
       * Return the matching value.
       */
      public String getValue() {
  
  	return (this.value);
  
      }
  
  
      /**
       * Set the matching value.
       *
       * @param value The matching value
       */
      public void setValue(String value) {
  
  	this.value = value;
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Conditionally evaluate the body content of this tag.
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
  
  	// Test the requested condition
  	boolean equals = false;
  	Object attribute = pageContext.getAttribute(name, getScopeId());
  	if (attribute != null) {
  	    String methodName = "get" + BeanUtils.capitalize(property);
  	    Class paramTypes[] = new Class[0];
  	    Method method = null;
  	    Object value = null;
  	    try {
  		method = attribute.getClass().getMethod(methodName, paramTypes);
  		value = method.invoke(attribute, new Object[0]);
  		if (value == null)
  		    value = "";
  	    } catch (NoSuchMethodException e) {
  		throw new JspException
  		  (messages.getMessage("htmlPropertyTag.method", methodName));
  	    } catch (Exception e) {
  		throw new JspException
  		  (messages.getMessage("htmlPropertyTag.result",
  				       methodName, e.toString()));
  	    }
  	    equals = this.value.equals(value);
  	}
  
  	// Conditionally evaluate the body of this tag
  	if (equals)
  	    return (EVAL_BODY_INCLUDE);
  	else
  	    return (SKIP_BODY);
  
      }
  
  
  
  }
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/taglib/IfPropertyNotEqualsTag.java
  
  Index: IfPropertyNotEqualsTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/IfPropertyNotEqualsTag.java,v 1.1 2000/06/16 01:32:24 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/06/16 01:32:24 $
   *
   * ====================================================================
   *
   * 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 java.lang.reflect.Method;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import org.apache.struts.util.BeanUtils;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * Conditionally include the body of this tag if the specified property
   * of the specified attribute (in any scope) has the specified value.
   *
   * @author Arun M. Thomas <ar...@ipin.com>
   * @version $Revision: 1.1 $ $Date: 2000/06/16 01:32:24 $
   */
  
  public class IfPropertyNotEqualsTag extends BaseAttributeTag {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The message resources for this package.
       */
      private static MessageResources messages =
  	MessageResources.getMessageResources
  	("org.apache.struts.taglib.LocalStrings");
  
  
      /**
       * The name of the property to get.
       */
      private String property = null;
  
  
      /**
       * The value to compare to.
       */
      private String value = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the property name.
       */
      public String getProperty() {
  
  	return (this.property);
  
      }
  
  
      /**
       * Set the property name.
       *
       * @param property The property name
       */
      public void setProperty(String property) {
  
  	this.property = property;
  
      }
  
  
      /**
       * Return the matching value.
       */
      public String getValue() {
  
  	return (this.value);
  
      }
  
  
      /**
       * Set the matching value.
       *
       * @param value The matching value
       */
      public void setValue(String value) {
  
  	this.value = value;
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Conditionally evaluate the body content of this tag.
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
  
  	// Test the requested condition
  	boolean equals = false;
  	Object attribute = pageContext.getAttribute(name, getScopeId());
  	if (attribute != null) {
  	    String methodName = "get" + BeanUtils.capitalize(property);
  	    Class paramTypes[] = new Class[0];
  	    Method method = null;
  	    Object value = null;
  	    try {
  		method = attribute.getClass().getMethod(methodName, paramTypes);
  		value = method.invoke(attribute, new Object[0]);
  		if (value == null)
  		    value = "";
  	    } catch (NoSuchMethodException e) {
  		throw new JspException
  		  (messages.getMessage("htmlPropertyTag.method", methodName));
  	    } catch (Exception e) {
  		throw new JspException
  		  (messages.getMessage("htmlPropertyTag.result",
  				       methodName, e.toString()));
  	    }
  	    equals = this.value.equals(value);
  	}
  
  	// Conditionally evaluate the body of this tag
  	if (!equals)
  	    return (EVAL_BODY_INCLUDE);
  	else
  	    return (SKIP_BODY);
  
      }
  
  
  
  }
  
  
  
  1.2       +1 -1      jakarta-struts/web/example/index.jsp
  
  Index: index.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/index.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- index.jsp	2000/05/31 22:28:10	1.1
  +++ index.jsp	2000/06/16 01:32:25	1.2
  @@ -8,7 +8,7 @@
   <body bgcolor="white">
   <h3><struts:message key="index.heading"/></h3>
   <ul>
  -<li><struts:link href="registration.jsp?action=Create"><struts:message key="index.registration"/></struts:link>
  +<li><struts:link href="editRegistration.do?action=Create"><struts:message key="index.registration"/></struts:link>
   <li><struts:link href="logon.jsp"><struts:message key="index.logon"/></struts:link>
   </ul>
   
  
  
  
  1.2       +1 -1      jakarta-struts/web/example/mainMenu.jsp
  
  Index: mainMenu.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/mainMenu.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- mainMenu.jsp	2000/05/31 22:28:10	1.1
  +++ mainMenu.jsp	2000/06/16 01:32:25	1.2
  @@ -13,7 +13,7 @@
   <h3><struts:message key="mainMenu.heading"/>
   <jsp:getProperty name="user" property="username"/></h3>
   <ul>
  -<li><struts:link href="editRegistration.do"><struts:message key="mainMenu.registration"/></struts:link>
  +<li><struts:link href="editRegistration.do?action=Edit"><struts:message key="mainMenu.registration"/></struts:link>
   <li><struts:link href="logoff.do"><struts:message key="mainMenu.logoff"/></struts:link>
   </ul>
   
  
  
  
  1.2       +11 -14    jakarta-struts/web/example/registration.jsp
  
  Index: registration.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/registration.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- registration.jsp	2000/05/31 22:28:10	1.1
  +++ registration.jsp	2000/06/16 01:32:26	1.2
  @@ -4,12 +4,12 @@
   
   <html>
   <head>
  -<struts:ifParameterEquals name="action" value="Create">
  +<struts:ifPropertyEquals name="registrationForm" property="action" value="Create">
     <title><struts:message key="registration.title.create"/></title>
  -</struts:ifParameterEquals>
  -<struts:ifParameterEquals name="action" value="Edit">
  +</struts:ifPropertyEquals>
  +<struts:ifPropertyEquals name="registrationForm" property="action" value="Edit">
     <title><struts:message key="registration.title.edit"/></title>
  -</struts:ifParameterEquals>
  +</struts:ifPropertyEquals>
   </head>
   <body bgcolor="white">
   
  @@ -17,6 +17,7 @@
   
   <struts:form action="saveRegistration.do" name="registrationForm"
                  type="org.apache.struts.example.RegistrationForm">
  +<struts:hidden name="action"/>
   <table border="0" width="100%">
   
     <tr>
  @@ -24,13 +25,13 @@
         <struts:message key="prompt.username"/>
       </th>
       <td align="left">
  -      <struts:ifParameterEquals name="action" value="Create">
  +      <struts:ifPropertyEquals name="registrationForm" property="action" value="Create">
           <struts:text name="username" size="16" maxlength="16"/>
  -      </struts:ifParameterEquals>
  -      <struts:ifParameterEquals name="action" value="Edit">
  +      </struts:ifPropertyEquals>
  +      <struts:ifPropertyEquals name="registrationForm" property="action" value="Edit">
           <struts:property name="username"/>
   	<struts:hidden name="username"/>
  -      </struts:ifParameterEquals>
  +      </struts:ifPropertyEquals>
       </td>
     </tr>
   
  @@ -97,13 +98,9 @@
     </tr>
   
   </table>
  -
  -<input type="hidden" name="action"
  - value="<struts:parameter name="action"/>">
  -
   </struts:form>
   
  -<struts:ifParameterEquals name="action" value="Edit">
  +<struts:ifPropertyEquals name="registrationForm" property="action" value="Edit">
   
   <div align="center">
   <h3><struts:message key="heading.subscriptions"/></h3>
  @@ -154,7 +151,7 @@
     <struts:message key="registration.addSubscription"/>
   </app:linkUser>
   
  -</struts:ifParameterEquals>
  +</struts:ifPropertyEquals>
   
   </body>
   </html>
  
  
  
  1.2       +1 -0      jakarta-struts/web/example/subscription.jsp
  
  Index: subscription.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/subscription.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- subscription.jsp	2000/05/31 22:28:10	1.1
  +++ subscription.jsp	2000/06/16 01:32:26	1.2
  @@ -20,6 +20,7 @@
   
   <struts:form action="saveSubscription.do" name="subscriptionForm"
                  type="org.apache.struts.example.SubscriptionForm">
  +<struts:hidden name="action"/>
   <table border="0" width="100%">
   
     <tr>
  
  
  
  1.2       +6 -6      jakarta-struts/web/example/WEB-INF/action.xml
  
  Index: action.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/WEB-INF/action.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- action.xml	2000/05/31 22:28:10	1.1
  +++ action.xml	2000/06/16 01:32:26	1.2
  @@ -7,8 +7,8 @@
        actionClass="org.apache.struts.example.EditRegistrationAction"
      formAttribute="registrationForm"
          formClass="org.apache.struts.example.RegistrationForm"
  -         success="/registration.jsp?action=Edit"
  -         failure="/mainMenu.jsp"
  +         success="/registration.jsp"
  +         failure="/logon.jsp"
     />
   
     <!-- Edit mail subscription -->
  @@ -33,7 +33,7 @@
      formAttribute="logonForm"
          formClass="org.apache.struts.example.LogonForm"
            success="/mainMenu.jsp"
  -         failure="/logon.jsp"
  +       inputForm="/logon.jsp"
     />
   
     <!-- Save user registration -->
  @@ -42,7 +42,7 @@
      formAttribute="registrationForm"
          formClass="org.apache.struts.example.RegistrationForm"
            success="/mainMenu.jsp"
  -         failure="/registration.jsp"
  +       inputForm="/registration.jsp"
     />
   
     <!-- Save mail subscription -->
  @@ -50,8 +50,8 @@
        actionClass="org.apache.struts.example.SaveSubscriptionAction"
      formAttribute="subscriptionForm"
          formClass="org.apache.struts.example.SubscriptionForm"
  -         success="/registration.jsp?action=Edit"
  -         failure="/subscription.jsp"
  +         success="/editRegistration.do?action=Edit"
  +       inputForm="/subscription.jsp"
     />
   
   </action-mappings>