Results 1 to 10 of 10
  1. #1
    Satheeshhere is offline Member
    Join Date
    Jul 2008
    Location
    chennai
    Posts
    9
    Rep Power
    0

    Post Struts validator framework

    Hi friends,

    Im new to struts framework and using struts1.3
    thing is i want to do client side validation using validator framework.

    server side validation (ie <html:erros> ) is working fine.but not client side validation.
    im using <html:javascript formName="Homeform">
    and <html:form action="/action.do" method="post" onsubmit="return validateHomeform(this);">

    Homeform is bean which extends ValidatorForm..

    but im not getting alertbox n all.can u guys pls help me


    If u r not able to understand means i can explain in detail.
    Lukin forward ur answers.

  2. #2
    ganesan is offline Member
    Join Date
    Jul 2008
    Posts
    6
    Rep Power
    0

    Default

    Hi you need to do the Homeform fields for client side validation using validation.xml file.

    for eg.........

    assume passwordfied and confirm password fields

    <form name="Homeform">
    <field property="password" depends="required,minlength">
    <arg0 key="home.password"/>
    <arg1 key="${var:minlength}" name="minlength" resource="false"/>
    <var>
    <var-name>minlength</var-name>
    <var-value>6</var-value>
    </var>
    </field>
    <field property="confirmpassword" depends="validwhen">
    <msg name="validwhen" key="errors.confirmpassword.match"/>
    <var>
    <var-name>test</var-name>
    <var-value>(*this* == password)</var-value>
    </var>
    </field>

    In Properties file
    home.password=password
    errors.confirmpassword.match=password does not match

    try to this logic you can get the output

  3. #3
    Satheeshhere is offline Member
    Join Date
    Jul 2008
    Location
    chennai
    Posts
    9
    Rep Power
    0

    Default

    Hi ganesan..thx much 4 ur reply.

    but i already defined validation.xml like this for "required" validation

    <form-validation>
    <formset>
    <form name="HomeForm">
    <field property="filepath" depends="required">
    <arg key="required.index" />
    </field>
    </form>

    i hav properties file also..
    and my validator-rules.xml looks like this

  4. #4
    Satheeshhere is offline Member
    Join Date
    Jul 2008
    Location
    chennai
    Posts
    9
    Rep Power
    0

    Default

    (CONTINUATION)

    <validator name="required"

    classname="org.apache.struts.validator.FieldChecks "

    method="validateRequired"

    methodParams="java.lang.Object,

    org.apache.commons.validator.ValidatorAction,

    org.apache.commons.validator.Field,

    org.apache.struts.action.ActionMessages,

    org.apache.commons.validator.Validator,

    javax.servlet.http.HttpServletRequest"

    msg="errors.required"/>
    Last edited by Satheeshhere; 07-15-2008 at 01:25 PM.

  5. #5
    Satheeshhere is offline Member
    Join Date
    Jul 2008
    Location
    chennai
    Posts
    9
    Rep Power
    0

    Default

    server side validation is working very fine..
    but stil couldnt get client side alert box.

    i think there s some thing wrong in my validatior-rules.xml for only client side validation.
    is it?

    Ganesh pls im awaitin for ur reply.thx in advance:)

  6. #6
    ganesan is offline Member
    Join Date
    Jul 2008
    Posts
    6
    Rep Power
    0

    Default

    Hi satheesh

    you should copy the validator error message from validator-rules.xml to properties file.


    1. In form bean u must extend ValidatorForm
    2. u put the plugins in struts-config.xml
    3. define the validation rules in validation.xml(for eg i was send previouse message)
    4. you need not to any change in validator-rules.xml file
    5.call java script code in jsp file


    follow this sure you can get the output
    Regards

    Ganesh

  7. #7
    Satheeshhere is offline Member
    Join Date
    Jul 2008
    Location
    chennai
    Posts
    9
    Rep Power
    0

    Default

    Hi ganesh.

    i have done all those things as u said properly.so that only my server side validation s working fine.

    thing is validator-rules.xml wat i have has some errors..

    Can you just send your validatior-rules.xml? it wil be helpful if u do that..

  8. #8
    anandguna is offline Member
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    0

    Default

    Make sure the javascript formname similar to the <form-bean> name mentioned in the struts config.xml file.

  9. #9
    rameshraj is offline Member
    Join Date
    Dec 2007
    Posts
    42
    Rep Power
    0

    Thumbs up

    For client side I think the javascript code should be used,what you have done using the validation.xml is processed on the server and so ur server side validation is working.Then go for javascript as used in almost all sites.Define the javascript method and call them when the form is submitted or some thing change happens in the form elements.

  10. #10
    beck is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Default

    Today I have the same problem, I'm using Struts1.1, its validator-rule.xml dtd is 1.0.
    I found you are validating a 'password' field, then I came across the problem that it can't alert a message when the field'e length is less then 'minlength' I defined in validation.xml. You can find the javascript code of function validateMinlength() in validator-rule.xml, there is a piece of follows:
    if (field.type == 'text' || field.type == 'textarea')
    so it won't validate field of 'password' type, you can change it to
    if(field.type == 'text' || field.type == 'textarea' || field.type == 'password')
    then it will work fine. I'm not sure whether it is a bug or there is some other reasons.

Similar Threads

  1. Struts Validator validwhen
    By getsridhara in forum Web Frameworks
    Replies: 0
    Last Post: 05-30-2008, 10:58 AM
  2. Struts Validator
    By anoop.retnakumar in forum Web Frameworks
    Replies: 1
    Last Post: 03-05-2008, 06:54 AM
  3. Struts Validator Framework
    By Albert in forum Web Frameworks
    Replies: 2
    Last Post: 02-15-2008, 11:01 AM
  4. Replies: 1
    Last Post: 07-06-2007, 04:39 PM
  5. Validator framework
    By Daniel in forum Web Frameworks
    Replies: 1
    Last Post: 06-25-2007, 05:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •