You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bailey, Shane C." <SH...@saic.com> on 2003/06/02 16:02:50 UTC

RE: Struts Validation Question

What does your action mapping look like in the struts-config?  Also, I
believe, by the time you are in the action validation will already be
performed (once you have it working properly).  So you don't have a call to
validate() or anything to do with validation in the action.


-----Original Message-----
From: Ranj Nadarajah [mailto:nadarajah2003@hotmail.com] 
Sent: Monday, June 02, 2003 10:03 AM
To: struts-user@jakarta.apache.org
Subject: Struts Validation Question

I've been trying to make validator work with our application.  However, I've

not been
very successful.  Here is what I did.  Please let me know if I missed 
anything.

I've created a form with firstName and LastName fields.  The validator 
should
see if that the form is not empty.  Howver, when I don't fill in and submit,

I get
to the next page.  I don't see the validator checking for errors and 
reporting.
I followed the guidelines in http://www.onjava.com/lpt/a/2912


1) Put the commons-validator.jar,jakarta-oro.jar and the struts.jar in the 
lib folder
2) Put the validator-rules.xml file in the web-inf directory.
3) created the validator.xml file in the web-inf directory and put the 
following in the
validation.xml file:

<form-validation>

    <!-- ========== Default Language Form Definitions ===================== 
-->
    <formset>

      <form  name="com.gdm.form.FBOrder">

         <field  property="firstName"
         	   depends="required,minlength">
         	     <arg0 key="orderForm.firstname.displayname"/>
                 <arg1 name="minlength" key="${var:minlength}" 
resource="false"/>
                     <var>
                       <var-name>minLength</var-name>
                       <var-value>5</var-value>
                     </var>
         </field>

        </form>

      </formset>


</form-validation>


4) Created the ActionForm class and extended it from validator.form

5) Called the ((FBOrder)form).validate(..) method from the action class

6) Created the following code in struts-config.xml

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


7) put the following code in the jsp page.

<logic:messagesPresent>
<bean:message key="errors.header"/>
<ul>
    <html:messages id="error">
      <li><bean:write name="error"/></li>
</html:messages>
</ul><hr>
</logic:messagesPresent>

7) Put the following in the applicationresources.properties file.
button.cancel=Cancel
button.confirm=Confirm
button.reset=Reset
button.save=Save

# Errors
errors.footer=
errors.header=<h3><font color="red">Validation Error</font></h3>You must 
correct the following error(s) before proceeding:
errors.ioException=I/O exception rendering error messages: {0}
error.database.missing=<li>User database is missing, cannot validate logon 
credentials</li>
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.

errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.

errors.date={0} is not a date.

errors.range={0} is not in the range {1} through {2}.

errors.creditcard={0} is not a valid credit card number.

errors.email={0} is an invalid e-mail address.

#Order Form
orderForm.firstname.displayname=First Name
orderForm.lastname.displayname=Last Name

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Struts Validation Question

Posted by Shashank Dixit <Sh...@datamatics.com>.
Test msg .. pls ignore....
Shashank S. Dixit Senior Software Engineer Datamatics Ltd. Contact: 28291253
ext 133 Mobile: 9820930075
----- Original Message -----
From: "Bailey, Shane C." <SH...@saic.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Monday, June 02, 2003 7:32 PM
Subject: RE: Struts Validation Question


>
> What does your action mapping look like in the struts-config?  Also, I
> believe, by the time you are in the action validation will already be
> performed (once you have it working properly).  So you don't have a call
to
> validate() or anything to do with validation in the action.
>
>
> -----Original Message-----
> From: Ranj Nadarajah [mailto:nadarajah2003@hotmail.com]
> Sent: Monday, June 02, 2003 10:03 AM
> To: struts-user@jakarta.apache.org
> Subject: Struts Validation Question
>
> I've been trying to make validator work with our application.  However,
I've
>
> not been
> very successful.  Here is what I did.  Please let me know if I missed
> anything.
>
> I've created a form with firstName and LastName fields.  The validator
> should
> see if that the form is not empty.  Howver, when I don't fill in and
submit,
>
> I get
> to the next page.  I don't see the validator checking for errors and
> reporting.
> I followed the guidelines in http://www.onjava.com/lpt/a/2912
>
>
> 1) Put the commons-validator.jar,jakarta-oro.jar and the struts.jar in the
> lib folder
> 2) Put the validator-rules.xml file in the web-inf directory.
> 3) created the validator.xml file in the web-inf directory and put the
> following in the
> validation.xml file:
>
> <form-validation>
>
>     <!-- ========== Default Language Form Definitions
=====================
> -->
>     <formset>
>
>       <form  name="com.gdm.form.FBOrder">
>
>          <field  property="firstName"
>             depends="required,minlength">
>               <arg0 key="orderForm.firstname.displayname"/>
>                  <arg1 name="minlength" key="${var:minlength}"
> resource="false"/>
>                      <var>
>                        <var-name>minLength</var-name>
>                        <var-value>5</var-value>
>                      </var>
>          </field>
>
>         </form>
>
>       </formset>
>
>
> </form-validation>
>
>
> 4) Created the ActionForm class and extended it from validator.form
>
> 5) Called the ((FBOrder)form).validate(..) method from the action class
>
> 6) Created the following code in struts-config.xml
>
>   <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
>     <set-property
>       property="pathnames" vaue="/WEB-INF/validator-rules.xml,
> /WEB-INF/validation.xml" />
>   </plug-in>
>
>
> 7) put the following code in the jsp page.
>
> <logic:messagesPresent>
> <bean:message key="errors.header"/>
> <ul>
>     <html:messages id="error">
>       <li><bean:write name="error"/></li>
> </html:messages>
> </ul><hr>
> </logic:messagesPresent>
>
> 7) Put the following in the applicationresources.properties file.
> button.cancel=Cancel
> button.confirm=Confirm
> button.reset=Reset
> button.save=Save
>
> # Errors
> errors.footer=
> errors.header=<h3><font color="red">Validation Error</font></h3>You must
> correct the following error(s) before proceeding:
> errors.ioException=I/O exception rendering error messages: {0}
> error.database.missing=<li>User database is missing, cannot validate logon
> credentials</li>
> errors.required={0} is required.
> errors.minlength={0} can not be less than {1} characters.
> errors.maxlength={0} can not be greater than {1} characters.
> errors.invalid={0} is invalid.
>
> errors.byte={0} must be an byte.
> errors.short={0} must be an short.
> errors.integer={0} must be an integer.
> errors.long={0} must be an long.
> errors.float={0} must be an float.
> errors.double={0} must be an double.
>
> errors.date={0} is not a date.
>
> errors.range={0} is not in the range {1} through {2}.
>
> errors.creditcard={0} is not a valid credit card number.
>
> errors.email={0} is an invalid e-mail address.
>
> #Order Form
> orderForm.firstname.displayname=First Name
> orderForm.lastname.displayname=Last Name
>
> _________________________________________________________________
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org