Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Why aren't there any good VaLang examples/tutorials. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why aren't there any good VaLang examples/tutorials.

    Hello,
    I admit to being new to spring, and I am looking to validate a simple form. When I saw how VaLang works, by not having to define a validation bean but instead just create an expression to validate a bean I got pretty excited. Finally, a simple, fast, and easy validation procedure.

    however, i can not get VaLang working. i downloading spring-modules 0.8, and i have scoured the net for a decent tutorial on server side validation, however i can not find one that explains things well enough. Hopefull this forum can help me out.

    I understand that in my *-servlet.xml file i should add something like this.

    [code]
    <bean id="myValidator" class="org.springmodules.validation.valang.ValangV alidator">
    <property name="valang">
    <value><![CDATA[
    { firstName : length(?) < 30 : 'First name too long' }
    { lastName : length(?) < 50 : 'Last name too long' }
    ]]></value>
    </property>
    </bean>
    [code]


    However, on my form, how do i ensure that the input fields firstName and lastName are subjected to this type of validation. Also, for multiple forms, do i just continue to fill the properties field with more names and validation conditions?

    Any tutorial that will clearly explain how to use valang would be appreciated. I just need to know what to add in my *-servlet.xml file, anything to the controller class, and what to add on the view to ensure it gets validated.

    I appreciate the help. THANKS! THANKS!

  • #2
    I surfed the net and tried so many different tutorials.
    for those who need it, The one that I followed to the T, and had it work successfully is this.

    http://www.i-proving.ca/space/Techno...MVC/Validation

    good luck to those embarking on valang. It is great once you figure out how it works.

    Comment


    • #3
      netvampire can you please provide me sample code of working example...
      It will be a gr8 help


      Regards,

      Comment


      • #4
        I hope this helps.

        In my dispatcher-servlet.xml file i have this type of validation working with valang

        Code:
            <bean id="registrationValidator" class="org.springmodules.validation.valang.ValangValidator">
                <property name="valang">
                    <value><![CDATA[
                    { userName : ? is not blank : 'User Name: required.' }
                    { userName : matches('\\w+',?) == true: 'User Name: Only Alpha-Numeric Characters' }
                    { userName : matches('\\w+',?) == true: 'User Name: Only Alpha-Numeric Characters' }
                    { userName : length(?) > 6 : 'User Name: Not between 6 - 12 characters.' }            
                    { userName : length(?) < 12 : 'User Name: Not between 6 - 12 characters.' }            
                    { firstName : ? is not blank : 'First Name: required.' }
                    { firstName : matches('\\w+',?) == true: 'First Name: Only Alpha-Numeric Characters' }
                    { lastName : ? is not blank : 'Last Name: required.' }
                    { lastName : matches('\\w+',?) == true: 'Last Name: Only Alpha-Numeric Characters' }
                    { email : ? is not blank : 'E-Mail: required.' }
                    { email : email(?) == true: 'E-Mail: Not A valid Address' }
                    { password : ? is not blank : 'Password: required.' }
                    { password : matches('\\w+',?) == true: 'Password: Only Alpha-Numeric Characters' }
                    { password : length(?) > 6 : 'Password: Not between 6 - 12 characters.' }            
                    { password : length(?) < 12 : 'Password: Not between 6 - 12 characters.' }            
                    { confirmPassword : ? is not blank : 'Confirm Password: required.' }
                    { confirmPassword : matches('\\w+',?) == true: 'Confirm Password: Only Alpha-Numeric Characters' }
                    { city : ? is not blank : 'City: required.' }
                    { age : matches('\\d+',?) == true: 'Age: Only Numeric Characters' }
                    { age : ? is not blank : 'Age: required.' }
                    ]]></value>
                </property>
            </bean>
        You may also need the correct library files to get this going (not sure, can't remember).

        Hope it helps.

        Comment


        • #5
          Hi everyone, you can get good Valang examples from the ¨Expert Spring MVC and Web flow¨ book. they are covering valang in a good level, so I suggest you to take a look at it.

          Comment

          Working...
          X