struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sharon Tam <ystam_2...@yahoo.com>
Subject Struts1.1 Validator
Date Sun, 25 Aug 2002 02:30:09 GMT

Hi,

Can anyone tell me what I might have done wrong so that the errors cannot be dectected even
if I submit the form with no input?  Thanks in advance!

I define the form and 2 actions in my sub-app configuration file called struts-checkout-config.xml:

<form-beans>

     <form-bean            name="addressForm"
                            dynamic="true"
                            type="org.apache.struts.validator.DynaValidatorForm">
          <form-property    name="title"     type="java.lang.String"/>
          <form-property    name="firstName" type="java.lang.String"/>
          <form-property    name="lastName"  type="java.lang.String"/>
          <form-property    name="address"   type="java.lang.String"/>
          <form-property    name="state"     type="java.lang.String"/>
          <form-property    name="city"      type="java.lang.String"/>
          <form-property    name="zip"       type="java.lang.String"/>
          <form-property    name="zipExt"    type="java.lang.String"/>
      </form-bean>

</form-beans>

     <action    path="/changeAddress"
                    name="addressForm"
                    parameter="/checkout/shipping.jsp"
                    scope="request"
                    type="org.apache.struts.actions.ForwardAction"
                    validate="false">
     </action>

     <action  path="/processChangeAddress"
                  name="addressForm"
                  type="com.ch.se.site.struts.actions.checkout.ChangeAddressAction"
                  input="/checkout/changeAddress.do"
                  scope="request"
                  validate="true">
          <forward     name="failure"        path="/checkout/shipping.jsp"/>
          <forward     name="success"      path="/welcome"/>
     </action>

  <message-resources parameter="ApplicationResources"/>

  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>

</plug-in>

Here's my validation.xml:

        <form name="addressForm">

            <field property="title"
                   depends="required">
                 <arg0  key="addressForm.title.displayName"/>
            </field>

            <field property="firstName"
                   depends="required,mask">
                <arg0   key="addressForm.firstName.displayName"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[a-zA-Z]*$</var-value>
                </var>
            </field>

            <field property="lastName"
                   depends="required,mask">
                <arg0   key="addressForm.lastName.displayName"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[a-zA-Z]*$</var-value>
                </var>
            </field>

            <field property="address"
                   depends="required">
                <arg0   key="addressForm.address.displayName"/>
            </field>

            <field property="city"
                   depends="required">
                <arg0   key="addressForm.city.displayName"/>
            </field>

            <field property="state"
                   depends="required">
                <arg0   key="addressForm.state.displayName"/>
            </field>

            <field property="zip"
                    depends="required,mask">
                <arg0   key="addressForm.zip.displayName"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^\d{5}</var-value>
                </var>
            </field>
        </form>


Here's my JSP:

  <html:errors/>

  <html:form action="/checkout/processChangeAddress.do">
      <!-- SHIPPING ADDRESSES -->
      <table cellpadding="0" cellspacing="2" border="0">
          <tr>      
              <td valign="top">
        </td>
          </tr>
        
          <tr>
       <td valign="top">
         Ship to Alternate Address:
    </td>
    <td>
        <table>
         <tr>
          <td>Title</td>
       <td><html:radio property="title" value="Mr.">Mr. &nbsp;&nbsp;</html:radio>
           <html:radio property="title" value="Mrs.">Mrs. &nbsp;&nbsp;</html:radio>
        <html:radio property="title" value="Ms.">Ms. &nbsp;&nbsp;</html:radio>
       </td>
      </tr>

      <tr>
          <td>First Name</td>
       <td><html:text property="firstName" size="20"/></td>
       <td>Last Name</td>
       <td><html:text property="lastName"  size="20"/></td>
      </tr>

      <tr>
          <td>Street Address</td>
       <td colspan="3"><html:text property="address" size="60"/></td>
      </tr>

      <tr>
          <td>City</td>
       <td><html:text property="city" size="20"/></td>
       <td>State &nbsp;&nbsp;&nbsp;
                         <td><html:select property="state" size="1">
               <html:option value="">Select One</html:option>
               <html:option value="NY">NY</html:option>
         <html:option value="NJ">NJ</html:option>
        </html:select>
       
       </td>        
      </tr>

      <tr>
          <td>Zip</td>
       <td><html:text property="zip" size="10"/>&nbsp;&nbsp;
           <html:text property="zipExt" size="20"/>
       </td>
      </tr>

      <tr>
          <td><html:submit property="submit" value="Submit"/></td>
      </tr>
    </table>
   </td>
         </tr>
   </table>
   </html:form>

 

Here are the extract from the log file:

[INFO] PropertyMessageResources - -Initializing, config='ApplicationResources', returnNull=true
[INFO] ValidatorPlugIn - -Loading validation rules file from '/WEB-INF/validator-rules.xml'
[INFO] ValidatorPlugIn - -Loading validation rules file from '/WEB-INF/validation.xml'

 



---------------------------------
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message