You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org> on 2012/05/17 18:02:07 UTC

[jira] [Comment Edited] (MYFACES-3547) Can't use expression for validator attributes

    [ https://issues.apache.org/jira/browse/MYFACES-3547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13277913#comment-13277913 ] 

Leonardo Uribe edited comment on MYFACES-3547 at 5/17/12 4:00 PM:
------------------------------------------------------------------

All validators extending from:

http://svn.apache.org/repos/asf/myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidatorBase.java

do not evaluate params on build view time, instead they are evaluated when validation is performed.

Look this example:

http://svn.apache.org/repos/asf/myfaces/commons/trunk/examples/myfaces-commons-facelets-examples/src/main/webapp/creditcardvalidator.xhtml

       <h:form id="myform">
            <p>Some valid test numbers</p>
            
            <ul>
              <li>Mastercard : 5555555555554444</li>
              <li>Mastercard : 5105105105105100</li>
              <li>Visa : 4111111111111111</li>
              <li>Visa : 4111111111111111</li>
              <li>Discover : 6011111111111117</li>
              <li>Discover : 6011000990139424</li>
              <li>American Express : 378282246310005</li>
              <li>American Express : 371449635398431</li>
            </ul>
            
            <h:panelGrid columns ="3">
              <h:outputLabel for="creditCardType" value="#{example_messages['credit_type']}" />
              <h:selectOneRadio id="creditCardType" value="#{validateCreditCard.creditCardType}" immediate="true">
                  <f:selectItems value="#{validateCreditCard.creditCardTypes}"/>
              </h:selectOneRadio>
              <h:message id="creditCardTypeError" for="creditCardType" styleClass="error" />
              
              <h:outputLabel for="creditCardNumber" value="#{example_messages['credit_number']}" />
              <h:inputText id="creditCardNumber" value="#{validateCreditCard.creditCardNumber}" required="true">
                  <mcv:validateCreditCard 
                      amex="#{mcc:findComponent('myform:creditCardType').value == 'AMEX'}"
                      visa="#{mcc:findComponent('myform:creditCardType').value == 'VISA'}"
                      discover="#{mcc:findComponent('myform:creditCardType').value == 'DISCOVER'}"
                      mastercard="#{mcc:findComponent('myform:creditCardType').value == 'MASTERCARD'}" />
              </h:inputText>
              <h:message id="creditCardNumberError" for="creditCardNumber" styleClass="error" />
            </h:panelGrid>
            <h:panelGroup/>
            <h:commandButton id="validateButton" value="#{example_messages['button_submit']}" action="#{validateCreditCard.submit}"/>
            <h:panelGroup/>
        </h:form>

The type has immediate="true", which ensures it is evaluated and set into the bean before the number, and in that way when the validation occur, the expression that refers to the type are evaluated first and taken into account. The same principle should work in ajax case.
                
      was (Author: lu4242):
    All validators extending from:

http://svn.apache.org/repos/asf/myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidatorBase.java

do not evaluate params on build view time, instead they are evaluated when validation is performed.

Look this example:

                  
> Can't use expression for validator attributes
> ---------------------------------------------
>
>                 Key: MYFACES-3547
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3547
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 2.1.7
>         Environment: validator ajax
>            Reporter: Deryk Sinotte
>            Priority: Minor
>         Attachments: validator.zip
>
>
> Attaching a test case that shows a problem when using an expression for an attribute in a validator. We have markup that looks like this:
> <h:inputText id="ajaxMy"
> value="#{testBean.myNumber}">
> <f:validateLongRange minimum="1"
> maximum="#{testBean.maxValue}"/>
> <f:ajax execute="@this"
> render="@form"/>
> </h:inputText>
> When the value of the maximum attribute is modified via Ajax from another input field, the value of the bean is properly set but the validator doesn't resolve appear to resolve the expression at the right time and the result is that validation occurs against the "old" values.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira