Results 1 to 5 of 5

Thread: Bean Validation Framework - Validation Context Tokens

  1. #1

    Red face 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 at 09:37 AM.

  2. #2
    Join Date
    Jun 2006
    Posts
    18

    Default

    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

  3. #3

    Thumbs up

    Quote 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 at 04:58 AM.

  4. #4
    Join Date
    Jun 2006
    Posts
    18

    Default

    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

  5. #5
    Join Date
    Aug 2010
    Posts
    1

    Default

    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,

Posting Permissions

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