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