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
Bean Validation Framework - Validation Context Tokens Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean Validation Framework - Validation Context Tokens

    Greeting Members..

    Can somebody suggest what is "Validation Context Tokens" and the usage of it w.r.t "Bean Validation Framework".


    Also, after going through validation xsd, i came across "method" element of "Class". Can somebody explain the usage of this element and how we can implement it.
    <class name="org.test.springmodules.validation.Person">
    .....
    <method name="" />
    .....
    </class>


    Your comments will be HIGHLY appreciated.

    Cheers!
    Last edited by theimmortalprogrammer; May 11th, 2007, 10:37 AM.

  • #2
    Hi,

    well, obviously it's a big oops on my part . These are actually two added features in 0.8 which weren't documented yet (already fixed in 0.9). The features are:

    1. Validation context support - now it is possible to define different validation contexts for the different validation rules. a validation context is identified by a context token (just a string at the moment) that can be assigned to rules. Along with that, BVF comes with proper interceptors by which the validation context can be defined.

    2. Validation Methods - it is possible to define validation methods in the bean. The validation method is a simple method that returns a boolean and that can do complex validation that may be harder to do with the out-of-the-box rules. This is an alternative to writing an external validator or extending the expression language.

    cheers,
    Uri

    Comment


    • #3
      Originally posted by uboness View Post
      1. Validation context support - now it is possible to define different validation contexts for the different validation rules. a validation context is identified by a context token (just a string at the moment) that can be assigned to rules. Along with that, BVF comes with proper interceptors by which the validation context can be defined.
      Thanks a ton for the reply. Helped me to some extent in understanding validation context.

      While going through the sources, I came across classes like "ValidationContextUrlMappingArrayPropertyEdito r" and "ValidationContextHandlerInterceptor". So do we need to configure the validation context for different URL patterns?

      Also we can specify an array of contexts in the validation.xml while defining validation rules:

      <class name="org.springmodules.Person">
      .....
      <method name="validateName" for-property="name" contexts="" />
      .....
      </class>

      I'm bit confused with the implementation part. Can you please explain the correct usage and provide a small implementation for Validation context tokens?

      Thanks in advance for your precious comments.

      Cheers!
      Last edited by theimmortalprogrammer; May 14th, 2007, 05:58 AM.

      Comment


      • #4
        for web application, you can assign different validation context tokens to different URLS:

        HTML Code:
        <beanid="validationContextInterceptor"class="..ValidationContextHandlerInterceptor">
        <propertyname="validationContextUrlMappings">
        <value>
        /user/*=ctx1,ctx2
        /admin/*=ctx3
        </value>
        </property>
        </bean>
        now, you can assign the 3 different tokens to the validation rules:

        HTML Code:
        @NotNull(contexts="ctx1,ctx2")
        privateStringbla;
        or

        HTML Code:
        <propertyname="bla">
        <not-nullcontexts="ctx1,ctx2"/>
        </property>
        Now, when the rules will be executed under the context of the "/usr/*" url but not under the "/admin/*" url.

        hope it helps
        Uri

        Comment


        • #5
          Hi,

          Sorry if i am posting in the wrong place. Where do/how do i inject the validationContextInterceptor. I tried doing it in the controller , but didn't help.

          Thanks,

          Comment

          Working...
          X