为什么isLocalValueSet()在这种情况下返回true?

时间:2016-04-28 14:28:00

标签: validation jsf jsf-2 lifecycle

考虑一下代码段:

<f:metadata>
        <f:viewAction onPostback="true" 
                      action="#{simpleBean.action}" 
                      phase="PROCESS_VALIDATIONS">
        </f:viewAction>
      </f:metadata>
    <h:head>
        <title></title>
    </h:head>
<h:body>
    <h:form>
        <h:inputText 
                    value="#{simpleBean.inputValue}" 
                    binding="#{simpleBean.htmlInputText}" 
                    validator="nameValidator" /><br/>
        <h:commandButton value="Submit" action="#{simpleBean.action}" />
        </h:form>
</h:body>

使用视图操作方法只打印有界组件属性。

        System.out.println(" getSubmittedValue() "+htmlInputText.getSubmittedValue());
        System.out.println(" isLocalValueSet() "+ htmlInputText.isLocalValueSet());
        System.out.println(" getValue() " + htmlInputText.getValue());
        System.out.println(" getLocalValue() " +htmlInputText.getLocalValue());

案例1)

  

如果[COMPONENT]标记为有效,则两者都返回相同的值,   即提交,转换和验证的值。

当在文本字段中输入值68时,&amp;提交 -

 getSubmittedValue() null
 isLocalValueSet() true
 getValue() 68
 getLocalValue() 68

情况2)

  

如果事先验证了UIInput组件并进行了标记   无效(即isValid()方法返回false),然后是   getLocalValue()返回null,但getValue()返回旧模型   值,如果有的话

当输入错误的值54@

 getSubmittedValue() 54@
 isLocalValueSet() false
 getValue() 5
 getLocalValue() null

我完全理解上述2个案例, 这是一个略有不同的测试用例:

案例3)

  

首次输入有效值

     

提交

     

输入错误的值

     

提交

 getSubmittedValue() null
 isLocalValueSet() true
 getValue() 68
 getLocalValue() 68

 getSubmittedValue() 90@
 isLocalValueSet() true     // WHY is this TRUE, even when validation failed
 getValue() 68              // WHY THESE PREVIOUS VALUES
 getLocalValue() 68         // WHY THESE PREVIOUS VALUES

0 个答案:

没有答案