问题
Here, it is mentioned by the author.
If it's[COMPONENT] marked valid, then both returns the same value, namely the submitted, converted and validated value.
Consider a very simple snippet:
<h:form>
<h:inputText value="#{bean.inputValue}"
binding="#{bean.htmlInputText}"
validator="nameValidator" /><br/>
<h:commandButton value="Submit" action="#{bean.action}" />
</h:form>
with a @RequestScoped
backing bean-
public Integer inputValue = 5;
public HtmlInputText htmlInputText;
public void action(){
System.out.println(" getSubmittedValue() "+htmlInputText.getSubmittedValue());
System.out.println(" isLocalValueSet() "+ htmlInputText.isLocalValueSet());
System.out.println(" getValue() " + htmlInputText.getValue());
System.out.println(" getLocalValue() " +htmlInputText.getLocalValue());
}
On pressing the submit button, output is-
getSubmittedValue() null AS EXPECTED, since Conversion & Validation succeded
isLocalValueSet() false
getValue() 25 AS EXPECTED, since Conversion & Validation succeded
getLocalValue() null Why NULL? IN WHAT CONTEXT HAS THE AUTHOR SAID SO
回答1:
You're checking the local value during invoke application phase.
The local value is cleared out during update model values phase.
The author is talking in context of process validations phase.
To clarify, here's the full process:
RESTORE_VIEW
- Restore
getSubmittedValue()
,isValid()
,getLocalValue()
andisLocalValueSet()
from JSF view state, if any.
APPLY_REQUEST_VALUES
- Do
setValid(true)
andsetSubmittedValue(request.getParameter(getClientId()))
.
PROCESS_VALIDATIONS
- Convert/validate
getSubmittedValue()
.- If valid, do
setValue(convertedAndValidatedValue)
,setLocalValueSet(true)
,setSubmittedValue(null)
. Do note thatsetValue()
effectively behaves assetLocalValue()
. - If invalid, do
setValid(false)
and skip update model values and invoke application phases.
- If valid, do
UPDATE_MODEL_VALUES
- If valid and local value set, do
bean.setProperty(getLocalValue())
and resetgetSubmittedValue()
,isValid()
,getLocalValue()
andisLocalValueSet()
to their default values ofnull
,false
,null
andfalse
.
INVOKE_APPLICATION
- Invoke
bean.method()
.
RENDER_RESPONSE
- If
getSubmittedValue()
is notnull
, render it, else ifisLocalValueSet()
returnstrue
, rendergetLocalValue()
, else renderbean.getProperty()
. - Save
getSubmittedValue()
,isValid()
,getLocalValue()
andisLocalValueSet()
in JSF view state, if changed.
来源:https://stackoverflow.com/questions/36907050/uiinputgetvalue-and-getlocalvalue-after-validation-succeeds-return-differen