Results 1 to 5 of 5

Thread: Beginning With Validation MVC - decision doubt

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default Beginning With Validation MVC - decision doubt

    Hello guys

    i am learning about Spring mvc (rookie in this topic only), reading a book of Apress called
    Expert Spring MVC and Web Flows

    first i used to work with struts and its validations (validation.xml and my own validations)

    well in the mentionated book, i saw that if the chapter (about validation) show 10 examples 1-2 is using the
    org.springframework.validation and the others use VaLang, so 10% against 90%,
    the chapter lack in my opinion of consistence of examples,
    so in a first glance seems that the book give to Valang how a better choice than validation.

    but in the documentation of Spring use of course validation (chapter 5)
    what type of validation i should use???, and why??, please share your knowledge

    Regards
    thanks for advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    I hope you find the book useful

    Anyways, the Spring validator is a very simple implementation agnostic strategy which enables you to validate your domain objects. There are a number of implementations, some of them are adapters or bridges to allow you to use external toolkits, like valang.

    If you are doing simple "check username isn't null, make sure age is > 0" etc. then taking advantage of a re-usable validation framework like valang or jakarta commons validator makes sense. OTOH if you need to do business specific validation (check the username isn't null) then you will need to write code.

    For what it is worth, for the hundreds of validators I have written, only one of them has used a 3rd party; commons validator, all the rest were hand rolled Going forward I would probably have a more even mix.

    Remember you can mix and match them as well so you could have both a valang validator and a hand rolled validator to validate the same object. Up to you

    You might also be interested in http://blog.interface21.com/main/200...my-first-post/
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello yatesco

    thanks for the reply,

    about the book, well i am starting read the chapter 10 ,
    and my unique critic could be for chapter 9 validation, lazy chapter. but the book
    was a good adquisition (nothing is perfect )

    well about validation, i thought that was enough with validation
    like the example of the chapter 5 of Spring Documentation

    but suppose that class Person have 2 more properties type Date called borndate and deaddate (sorry for my grammar)
    its obvious that 2 validation could be, if its ( null or blank ) and format for each variable of course

    but what about of ranges???, its silly that deathdate could be minor that borndate

    so in if in the validation class

    Code:
    public void validate(Object obj, Errors e) {
            ValidationUtils.rejectIfEmpty(e, "name", "name.empty");
            Person p = (Person) obj;
            if (p.getAge() < 0) {
                e.rejectValue("age", "negativevalue");
            } else if (p.getAge() > 110) {
                e.rejectValue("age", "too.darn.old");
            }
    	if(staticvariabletoglobalclassvalidation.validaterangedates(borndate,deathdate)){ // <--- used by other class validator's
    		e.rejectValue("borndate", "it imposible live after death");
    	}
        }
    }
    of course that validaterangedates was made by hand by myself, and other validation methods, using special validations with regex, (check telephones,postal,code etc etc) and used by other class validator's

    my point is that i have already written these clases for validation in a work with struts (used how utils class), so i want recicle these clases for Spring mvc, i hope you see my point, (maybe this is your point when you talk about mix )

    in my honest opinion i can work in peace with ValidationUtils and Errors using my clases validation
    if this logic or way is correct.

    is this really your way???, i am little confuse

    regards
    thanks for advanced

    DrPompeii
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    I am not really sure what you are asking

    Is it OK to hand roll your own validation; sure. What you have looks fine
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  5. #5
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello yatesco


    Quote Originally Posted by yatesco View Post
    Is it OK to hand roll your own validation; sure. What you have looks fine
    if is fine the logic and code that i written, for the dates, thanks, that was my principal doubt

    Quote Originally Posted by yatesco View Post
    I am not really sure what you are asking
    was about of the logic, if it is the correct way that you use when you make your own validations

    regards and thanks for the reply
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

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