Answers-

The great thing about the validation framework is that it does both CLIENT side 
validation with Javascript (if possible), but ALSO server side validation. If the user 
doesn't have Javascript enabled, it will validate on the server. (Even if Javascript 
is enabled, it will double check the validation on the server.)

After making the changes below, when you bring up the jsp in a browser, look at the 
source. It should have Javascript in it for the validations. If not, then your 
validator servlet (specified in web.xml) is probably not loading properly.

One other thing I had a problem with is the order that the struts controller and 
validator were loading. In the struts controller servlet, I put 
<load-on-startup>1</load-on-startup>, in the validator, I put 
<load-on-startup>2</load-on-startup>. (again in web.xml)

This fixed my issue.

HTH,
Ryan




>>> [EMAIL PROTECTED] 07/10/01 04:28PM >>>
Thanks for the comments. I have a few follow-ups interspersed with your
responses below...

David

Ryan Cornia wrote:
> 
> Yes, it works great.
> 
> A couple of things to check -
> 
> 1.) In the JSP page that is your form, make sure you have -
> 
> <html:form action="/myAction" onsubmit="return validateMyExampleForm(this);">
> 
> the onsubmit piece is what causes the validation.

Isn't this required only for client-side validation via Javascript? For
example, Right now, I am simply stating that I want the required check
to be performed. In the valiation.xml file for this, there appears to be
both a java (server-side) mechanism and a javascript (client-side)
mechanism. I am not sure that we can count on javascript so I was
focused on the server-side.

> 
> 2.) At the bottom of the JSP form, set the form name so the validator know what is 
>being validated -
> <validator:javascript formName="MyExampleForm"/>

See my note above.

> 
> Other than that, you should be set.
> 
> Ryan

Thanks Ryan.

> 
> >>> [EMAIL PROTECTED] 07/10/01 01:33PM >>>
> I have a small and simple web app that I have working with vanilla
> struts. I am trying to incorporate the struts validator mechanism by
> converting just one form. To do so, I have done the following:
> 
>         Placed the Struts_Validator-20010702.jar into the web app's lib dir.
> 
>         Place the jakarta-regexp-1.2.jar into the web app's lib dir.
> 
>         Place the struts-validator.tld into the web app's WEB-INF dir
> (along with the struts tag lib files).
> 
>         Copy the example validation.xml file into the web app's WEB-INF
> dir. Removed all but one form from the default (no locale) formset.
> Edited each field so that it depends on "require" only. Removed all the
> localized formsets.
> 
>         Cut & paste from the validator servlet definition from the
> example web.xml into mine. Changed the taglib reference for the
> validator taglib (no tld durectory).
> 
>         Changed the jsp to use the validator:errorsExist tag in place of
> the struts errors tag. Added the validator tag lib to the page.
> 
>         Changed the form class so that it extends ValidatorForm rather
> than struts ActionForm. Commented out my previously coded validate()
> method in the form class.
> 
>         In the form's action class, remove the check for errors in the
> perform() method.
> 
>         Added validate="true" to the form's action in the struts-config.xml
> file.
> 
> When I submit the page with empty fields, no errors are reported and the
> form's action just marches merrily along forwarding to the next jsp
> which fails because parameters are empty. I have looked and tried again
> and again with no luck. Before I give up, I thought I'd ask for help
> here. Any ideas as to what I am missing?
> 
> Thanks In Advance,
> 
> David
> Seattle

Reply via email to