You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John <jo...@yahoo.com> on 2002/12/17 19:46:23 UTC

Server side RegExp validation fails yet client side works (using DynaValidatorForm)

I'm currently using the Struts 1.1b version. I have a
problem where I define a simple form with a single
field; I need to have the field validated using
"required", "minlength" and "mask" validation
operators. I'm using DynaValidatorForm's to avoid the
overhead of implementing a concrete ActionForm class. 

When the client-side validation tags are inserted into
the JSP file, all three (client-side) validation
operators work perfectly. 

I commented out the <html:javascript> code and
onsubmit handler in the JSP file to test the server
side validation. (Is there an easier way?)

When I did this, the server side only validated with
the "required" and "minlength" validators...it seemed
to totally disregard the "mask" validation operation. 

I searched all of the FAQ's and google search result
sets and couldn't find anything quite like this...
Has anybody else experienced this? Am I missing
something?

(I realize that the regular expression I'm using
evaluates to digits only and that I could try using an
existing validation like "int". I found, however, that
the client side (javascript) implementation of
parseInt() is not what I'm looking for since "12fga"
will "pass" the parseInt() call)

Thank you for looking at my problem!

Here are the details; I'm using the un-modified
version of validator-rules.xml that shipped with the
struts1.1b jar file.

Here are the other files:

----> FILE: <-----------------
----> offerDetails.jsp <-----
--> (Note: client side validation has been removed)<--


<%@ taglib uri="/WEB-INF/struts-html.tld"
prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld"
prefix="bean" %>

<HTML>
<HEAD>
<TITLE>offerDetails.jsp</TITLE>
</HEAD>
<BODY>
	<H3>Offer Details Page</H3>
	<html:errors/>
	<html:form action="/GetDates" method="post">
	  Type in offer number:
	  <input type="text" name="offerId">
	  <input type="submit" name="submit">
	</html:form>
</BODY>
</HTML>

----> FILE: <-----------------
----> struts-config.xml <-----

<struts-config>
  <form-beans>
    <form-bean name="offerDetailsForm"  
type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="offerId"
type="java.lang.String"/>
    </form-bean>
  </form-beans>

  <action-mappings>
    <action path="/GetDates" validate="true" 
type="com.mycompany.reservation.myaccount.room.GetDatesAction"

				name="offerDetailsForm" input="/offerDetails.jsp">
			<forward name="success" path="/roomDates.jsp"/>
			<forward name="skipdate" path="/roomPrefs.jsp"/>
			<forward name="failure" path="/offerDetails.jsp"/>
		</action>
  </action-mappings>
  <message-resources
parameter="com.mycompany.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>

</struts-config>


----> FILE: <-----------------
----> validation.xml <-----

<?xml version="1.0"?>
<form-validation>
 <formset>
  <form name="offerDetailsForm">
   <field property="offerId"
depends="required,minlength,mask">
   <msg name="mask" key="numbers.only"/>
   <arg0 key="offerDetails.offerId.displayname"/>
   <arg1 name="minlength" key="${var:minlength}"
resource="false"/>
    <var>
     <var-name>mask</var-name>
     <var-value>^[0-9]*$</var-value>
    </var>
    <var> 
     <var-name>minlength</var-name>
     <var-value>5</var-value>
    </var>
   </field>
  </form>
 </formset>
</form-validation>


----> FILE: <-----------------
----> ApplicationResources.properties <-----
----> (abbreviated) <--------

errors.header=<h3><font color="red">Error
List</font></h3><ul>
errors.footer=</ul><hr>
offerDetails.offerId.displayname=Special Identifier
errors.required={0} is required.
errors.minlength={0} cannot be less than {1}
characters.
errors.invalid={0} is invalid.
numbers.only=Data must be comprised of numbers only.



Cheers!
johnmarch1966@yahoo.com


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Server side RegExp validation fails yet client side works (using DynaValidatorForm)

Posted by Chris Trawick <ct...@cultured.net>.
Knowing this isn't helping, I'm having the same problem only it doesn't even
get to the minlength validation.  Only the required.  My descriptors are
XDoclet generated.  Struts 1.1b2, JBoss 3.0.4 (Jetty), XDoclet 1.2.0.  If
anyone figures this out, please let us know.

chris

----- Original Message -----
From: "John" <jo...@yahoo.com>
To: <st...@jakarta.apache.org>
Sent: Tuesday, December 17, 2002 1:46 PM
Subject: Server side RegExp validation fails yet client side works (using
DynaValidatorForm)


> I'm currently using the Struts 1.1b version. I have a
> problem where I define a simple form with a single
> field; I need to have the field validated using
> "required", "minlength" and "mask" validation
> operators. I'm using DynaValidatorForm's to avoid the
> overhead of implementing a concrete ActionForm class.
>
> When the client-side validation tags are inserted into
> the JSP file, all three (client-side) validation
> operators work perfectly.
>
> I commented out the <html:javascript> code and
> onsubmit handler in the JSP file to test the server
> side validation. (Is there an easier way?)
>
> When I did this, the server side only validated with
> the "required" and "minlength" validators...it seemed
> to totally disregard the "mask" validation operation.
>
> I searched all of the FAQ's and google search result
> sets and couldn't find anything quite like this...
> Has anybody else experienced this? Am I missing
> something?
>
> (I realize that the regular expression I'm using
> evaluates to digits only and that I could try using an
> existing validation like "int". I found, however, that
> the client side (javascript) implementation of
> parseInt() is not what I'm looking for since "12fga"
> will "pass" the parseInt() call)
>
> Thank you for looking at my problem!
>
> Here are the details; I'm using the un-modified
> version of validator-rules.xml that shipped with the
> struts1.1b jar file.
>
> Here are the other files:
>
****  snip *****


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>