How to split validation.xml into more smaller validation files

Discussions

Web tier: servlets, JSP, Web frameworks: How to split validation.xml into more smaller validation files

  1. Hi,

    Does anyone know how do I split the validation.xml to many different validation XML files?
    The purpose to do it is that you know the stuff in the single validation.xml is too much and make it hard to maintain.I hope I can have more validation files like validationForStudent.xml,validationForTeacher.xml,etc.And these are for different cases.

    Thanks in advance.

    FS
    (email:fushengsong at hotmail dot com)

    Threaded Messages (15)

  2. Sorry,I forgot to mention that I talked about STRUTS stuff.
    Thanks
    FS
  3. Unless I'm misunderstanding your question, can you just add additional XML files to the "value" attribute? Here's an example of the plugin in the struts-config.xml to hook in the Validator to Struts:

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

    Notice the files in the value attribute of the <set-property> element are comma-seperated. Just add additional files there, seperated by a comma of course.

    Chuck
  4. Hi,
    Thank you very much to response.
    I mean I have 2 validation xml files (for example validation.xml,accreditation.xml)for validation purpose.
    One is used to validate general stuff,another is used to validate specific case.<br>
    (And validator-rules.xml for rules purpose)<br>
    How do I config?

    <p>
    I did according to your suggection.
    like?:
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathname" value="/WEB-INF/config/validator-rules.xml"/>
            <set-property property="pathname" value="/WEB-INF/config/validation.xml,/WEB-INF/config/validation/accreditation.xml"/>
          </plug-in>

    <br>But I got errors saying:
    ERROR - Skipping vali
    ation rules file from '/WEB-INF/config/validation.xml,/WEB-INF/config/validatio
    /accreditation.xml'. No stream could be opened.

    <br>
    Thanks

    Frank
  5. In newer versions of the Validator, the property name "pathname" was changed to "pathnames". Notice the "s" on the end. Your fragment shows the old way of specifying the files. Try the way that I showed you, unless you are using an old copy. Also, make sure the files are in the path that you specify.
    chuck
  6. In newer version of struts, multiple declaration of <set-property> is not supported.
    you should use a single set-property element that specifies multiple Validator resource files, separated by a comma. Also notice that the property value is the plural pathnames.

    I don't think we can use more than one file, although you can reduced you validations by using other functionalities like ActionForm or DynamicAction form.

    Amit.
  7. Hi:
    First,I am new to the struts and thanks for help.

    This validator that I am using seems not support the 'pathnames'.
    Could you tell me where I can get the source of newer version that you mentioned?

    On the other hand,if I still use the current validator that I have,probably I have to change other java file?
    I tried to config like:
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathname" value="/WEB-INF/config/validation.xml"/>
    <set-property property="pathname" value="/WEB-INF/config/validation/instructorExpertise.xml"/>
    <set-property property="pathname" value="/WEB-INF/config/validator-rules.xml"/>
          </plug-in>
    Result is the last validation file will overwrite the first one.
    But I checked the source ValidatorPlugIn.java and ValidatorResourcesInitializer.java,And I can not find problem.

    Thank you very much.

    Frank

     
    If I still use my
  8. You definitely have an older copy. You can get the latest either with a download of one the latest nightly builds of Struts or from the Jakarta Commons Project site. The Validator has been added there:

    http://jakarta.apache.org/commons

    Chuck
  9. Hi frank,

    As Chuck has suggested you must get the latest version of struts framework (1.1b). This framework supports only single entry for set-porperty in plug-in defination, as I mentioned earlier.
    I would also like to include that this validator.xml is basically used for client side validations. If you want to put server side validations you must use ActionForms or Dynamic actionforms(supports validation without creating any file or extra xml file, supported by struts 1.1) which will also help you in reducing the length of xml file.

    Amit.
  10. Amit,

     Respectfully, I must disagree with what you said. The Validator can spit out JavaScript (let's call that client-side validation) and it can be used with the DynaValidatorForm and DynaActionValidationForm (let's call this server side), and as I discuss in Chapter 11 of my upcoming Struts book, you can actually use it to validate in the business tier. Here's a link to the draft copy of Chapter 11 https://www.theserverside.com/resources/strutsreview.jsp.

    Although it's definitely not designed to replace business logic validation, it can be used for certain validation rules in the business tier.

    Maybe I misinterpreted what you were saying. Is so, sorry.

    Chuck
  11. Hi Chck,

    thanks for the updating me. I have not worked with Validtor as yet so may be i am worng.

    but, i am very glad to know that you are the man behind the Struts book for review on theserverside.com .

    I have one confusion about validation in struts, if I am not wrong the validation in action form or through xml file will take the network processing. For the Internet application it is not feasible to make client waiting for small error made by him.
    Do we have any way to resolve the network processing using struts or we have to use Javascript for that?
    It will be great if you can provide any example.

    pls comment.

    email: amit at direct2s dot com

    thanks.

    Amit.

  12. Hi,
    Thanks for you JURU's help.

    I updated my validtor to the latest one(It support the pathnames property).But another problem happened is when I config 2 validator file like:
    <set-property property="pathnames"
    value="/WEB-INF/config/validator-rules.xml,
    /WEB-INF/config/validation/instructorExpertise.xml,
    /WEB-INF/config/validation.xml"/>

    The last xml file will overwite the first xml file.I mean the first one is not working,only the last one. instructorExpertise.xml does not work for my case.

    Anything wrong for me?
     
    Thanks

    Frank

  13. I just searched the Apache bug database and that is a reported bug. The status still looks like it's not fixed yet. Here's the link to the bug report:

    http://issues.apache.org/bugzilla/show_bug.cgi?id=10584

    You might check the site of the Valdiator project and see if there's a new version that's just not been included with Struts yet. Here's the site:

    http://cvs.apache.org/viewcvs/jakarta-commons/validator/

    I would also search the Struts user and dev mailing list for this topic. I know I've seen several posts about this.

    chuck
  14. The only way that I'm aware of doing client-side validation (validation with issuing a request to the server), is through JavaScript. The Validator is capable of using static and dynamic JavaScript Validation. Static Validation using JavaScript will allow the browser to cache the file and therefore it won't have to download it each time. Check the Validation documentation on how to do this. I talk about this topic very briefly in Chapter 11.

    Chuck
  15. Hi:
    Thanks for your info.

    I looked at the source code in ValidatorResources.java.
    The problem is that it is using FastHashMap Object to hold the formset info and the last one will replace the first one because they use the same key name (calling buildKey(fs))

    Please continue to post if you have idea how to fix that bug right away.

    Thanks

    Frank
      

  16. I would post a question to struts user and ask if this has been fixed. You'll probably get a response from the creator of the Valdiator "David Winterfeldt". I know he monitors the list pretty regularly.

    chuck