Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

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.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
How to set the Valang rules optional depending on the request parameter? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set the Valang rules optional depending on the request parameter?

    Hi all.

    I have the following typical configs for Valang validator in the servlet.xml:

        <bean name="paymentDetailsController" class="eq.paymentDetailsController">
            <property name="commandClass" value="eq.UserPaymentDetails"/>
            <property name="validators">
                    <ref bean="creditCardDetailsValidator"/>
                    <ref bean="creditCardOwnerDetailsValidator"/>
     <bean name="creditCardDetailsValidator" class="org.springmodules.validation.valang.ValangValidator">
            <property name="valang">
    { cvvCode           : (? IS NOT NULL) AND (match('^\\d+$', ?) = true) : 'CVV code is required' : 'errors.required' : 'CVV code' }
    { cardNumber        : (? IS NOT NULL) : 'Card number is required' : 'errors.required' : 'Credit card number' }
    { expirationMonth   : (? > 0) AND (length(?) <= 2) : 'Expiration month is required' : 'errors.required' : 'Expiration month' }
    { expirationYear    : (? > 0) AND (length(?) == 4) : 'Expiration year is required'  : 'errors.required' : 'Expiration year' }
    // and so on

    The thing is that this validation should be optional on the page where the payment details are submitting. The user can choose the CreditCard method of payment (and the validation should be here then) or , for ex., some internet-wallet payment method (GiroPay, PayPal etc). In the latter case no validation should be because of user data is entered on the external pages which has their own validation rules. How to bring this idea into the configs above?

    The given controller will know the chosen payment method only after the user submits the html-form from the web. And some option box with name paymMethod and values "Creditcard" or "Paypal" should determine the necessity of using of the described valang rules.

    Or once again in other words: how to 'disable' the creditCardDetailsValidator bean dynamically?

    Thanks for any help.