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
How to set the Valang rules optional depending on the request parameter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
        <bean name="paymentDetailsController" class="eq.paymentDetailsController">
            <property name="commandClass" value="eq.UserPaymentDetails"/>
            <property name="validators">
                <list>
                    <ref bean="creditCardDetailsValidator"/>
                    <ref bean="creditCardOwnerDetailsValidator"/>
                </list>
            </property>
        </bean>
    
     <bean name="creditCardDetailsValidator" class="org.springmodules.validation.valang.ValangValidator">
            <property name="valang">
                <value><![CDATA[
    { 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
    
    ]]>
                </value>
            </property>
        </bean>

    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.
Working...
X