Why does isLocalValueSet() returns true in this case?

ε祈祈猫儿з 提交于 2019-12-11 11:10:08

问题


Consider the snippet:

<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>

with view action method just printing the bounded component properties.

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

Case1)

If it's[COMPONENT] marked valid, then both returns the same value, namely the submitted, converted and validated value.

When one enters a value of 68 in the text field & submits-

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

Case2)

If the UIInput component has been validated beforehand and is marked invalid (i.e. isValid() method returns false), then the getLocalValue() returns null, but the getValue() returns the old model value, if any

When one enters an incorrect value like 54@

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

I perfectly understood the 2 above cases, Here's a slightly different test case:

Case3)

Enter a valid value first time

Submit

Enter an incorrect value

Submit

 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

来源:https://stackoverflow.com/questions/36917652/why-does-islocalvalueset-returns-true-in-this-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!