client side validation using struts
6 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Heema_Shah
Posted On:   Thursday, July 4, 2002 07:03 AM

I need to implement client side validation using the struts frame work. kindly help

Re: client side validation using struts

Posted By:   Marian_Skalsky  
Posted On:   Wednesday, July 10, 2002 05:15 AM

Check this page:

http://www.theserverside.com/resources/strutsreview.jsp
, register and download the chapter (if it still makes sence for you) about VALIDATION(doc/rtf file). I was looking for answers about validation a lot, especaly to get som all-inclusive overview, and I found it there!


$kala

Enabling client/server side validation..

Posted By:   Marian_Skalsky  
Posted On:   Monday, July 8, 2002 04:49 AM

I found something
about this in JGuru forums:



" In your JSP file containing



onsubmit="return validateFindAppForm(this);"



add this to the bottom just before you close your html body.







Adding the above will add in Client side (Java Script) Validation
.




If you want to have Server Side Validation, try this.


In your FindAppAction
Class (Your Action Class) try putting in this method.


public ActionForward
perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response)

throws IOException, ServletException {


RegistrationForm
info = (RegistrationForm)form;

ActionErrors errors = info.validate(mapping, request);

saveErrors(request, errors);

return mapping.findForward("success");

}"


May be useful.


$kala.




Re: client side validation using struts

Posted By:   Marian_Skalsky  
Posted On:   Monday, July 8, 2002 02:10 AM

Hi!


I found out that
there is a attempt to provide some tutorial about validation by jakarta. But
nothing there yet.
http://jakarta.apache.org/struts/userGuide/dev_validator.html


$kala

Re: client side validation using struts

Posted By:   Marian_Skalsky  
Posted On:   Monday, July 8, 2002 01:57 AM

Hi there.

I'm looking for
the same answer as you (probably). If you wanna use client side JavaScript validation,
this may help you.


Validation


Validation is already
a part of Struts.. it used to have a seat at when it was not: http://home.earthlink.net/~dwinterfeldt/.
Now it is also at: http://cvs.apache.org/viewcvs/jakarta-commons/validator/.


Setup

  • files necessary
    to setup the validator:


    • validator-rules.xml
      (if you don't want to define own validator you don't need to toch it)


      • defines
        validation rules (+their Javascript) defined in org.apache.struts.validator.util.StrutsValidator
        such as:

        · field is required

        · specified length

        · matches a regular expression

        · email

        · credit card

        · server side type checking


        · date validation

        · other..
        plus
        you may define your own validation rules as validation plugins




    • validation.xml
      (here you have to define validations for your specific formbeans)


      • defines
        global constants used by validation plugins

      • different
        validation rules can be defined for different locales by seting a
        formset

      • each
        formset defines group of properties specific for the form and their
        "limitations" with specific values e.g. :


        • form
          bean name


          • field
            name


            • required
              (true/false)


            • mask (regular expresion)

            • minlenght
              (size)



          • field
            name


            • required
              (true/false)

            • email



          • etc.







    • web.xml


      • locates
        validator taglibs (probably)



    • struts-config.xml
      - this has to be added


      • Message
        Resources Definition - "

      • Plug
        Ins Configuration -




      • ApplicationResources.properties
        (+language versions) - define error messages such as errors.required,
        errors.minlength etc. (errors.maxlength={0} can not be greater than
        {1} characters) + header and footer





  • custom validation
    routines can be created and added to the framework

  • different validation
    rules can be defined for different locales

  • support for
    user defined constants which can be used in some field attributes

  • JavascriptValidatorTag
    - used to generate javascript validations on client side, based on the validation
    rules loaded by the Validator


  • Usage

    • use as:

      • extend
        org.apache.struts.validator.action.ValidatorForm instead of org.apache.struts.action.ActionForm

      • form
        element's name attribute in the validation.xml should match action
        element's name attribute.



    • or as:


      • extend
        the ValidatorActionForm

      • action
        element's 'path' attribute from the struts-config.xml which should match
        the form element's name attribute in the validation.xml





Internationalization



  • Validation rules
    for forms can be grouped under a FormSet in the validation.xml file.

  • FormSet has
    language, country, and variant attributes that correspond with the java.util.Locale
    class


Pluggable Validators

There are predefined validators as shown above, but you may define your own
validator. Then you define it as:

Example Validator Configuration from validation.xml.



classname="org.apache.struts.validator.util.StrutsValidatorUtil"

method="validateRequired"

msg="errors.required"/>


Have a Submit
Button in a Form not Perform Validation


If you want to turn off the validation for a specific submit button like the
html:cancel tag, you can set the bCancel variable to true for the JavaScript
validation not to execute and bCancel to false for it to execute.


onclick="bCancel=false;">




Client
side validation


I'm still not
sure about how to get JS validation work at client side.. if it is only in presence
of "onsubmit="return validateRegistrationForm(this);" in the
form tag of jsp... will see. I have downloaded older Validator from http://home.earthlink.net/~dwinterfeldt/archive/
and there is working example but with no extra comment and without source codes..
But I have already seen validation window appear at client, telling me what
should be and is not valid :)) So, it works :))


Now
I'm waiting for these questions to be answered from David Winterfeldt
:



  • Where can I
    find some working example (+source code of Actions etc!) to see how it (the
    validation) works?

  • Is there any
    serious tutorial about "validation in struts" ?

  • Where can I
    find more obout validation at jakarta home page ? (I found only: http://cvs.apache.org/viewcvs/jakarta-commons/validator/)



When answered,
I'll publish.


Hope helped a bit.
Digging around :))


$kala.






Re: client side validation using struts

Posted By:   Val_Pecaoco  
Posted On:   Friday, July 5, 2002 03:39 AM

Hi Heema,




Struts has so-called ActionForm objects which acts like a filter before a form gets POSTed. You can do validation by overiding the validate() method and providing your own code. Just tell Struts that this form has a corresponding ActionForm object (this is done in struts-config.xml), and Struts will do the binding automatically for you.




Hope that helps.




-- Val

Re: client side validation using struts

Posted By:   Marian_Skalsky  
Posted On:   Thursday, July 4, 2002 07:08 AM

You should check if your question is not already answered somewhere before you submit your question..
I'm askin the same 3 titles below.. :)
http://jguru.com/forums/view.jsp?EID=938305


$kala
About | Sitemap | Contact