You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sharon Tam <ys...@yahoo.com> on 2002/08/25 04:30:09 UTC
Struts1.1 Validator
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. </html:radio>
<html:radio property="title" value="Mrs.">Mrs. </html:radio>
<html:radio property="title" value="Ms.">Ms. </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
<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"/>
<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
Re: Struts1.1 Validator
Posted by Rob Leland <rl...@apache.org>.
Sharon Tam wrote:
> 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!
When I fixed a bug earlier today submitted by James,
in determining if the fix was consistent with the existing
behaviour I discovered Passing in no value consistently does not return
errors in the ActionErrors. The behaviour is to
return 'null' for an Object, or false in the case of a boolean.
I took the time to add a few comments to the Struts Validator code
so hopefully this will make it a bit more clear in the future.
I have never used the validator myself, so that is the
end of my insight.
-Rob
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>