I have gone through this, but the answer is not very clear to me. Hence asking,
For the validate method of the class UIInput
, we have this (Marking only those lines which are related to the question)
public void validate(FacesContext context) {
Object submittedValue = getSubmittedValue(); // LINE 958
newValue = getConvertedValue(context, submittedValue); // LINE 976
validateValue(context, newValue); // LINE 983
if (isValid()) { // LINE 987
Object previous = getValue();
setValue(newValue); // LINE 989
setSubmittedValue(null);
}
}
If both Conversion & Validation succeeds, then isValid()
returns true
.
The component's local
value is then set - setValue(newValue)
, indicated by the flag setLocalValueSet(true)
After that, the submitted
value is set to null - setSubmittedValue(null)
If you look at the code for this setValue(...) method of UIInput, it is overridden,
@Override
public void setValue(Object value) {
super.setValue(value);
// Mark the local value as set.
setLocalValueSet(true);
}
So from LINE 989, the call delegated to this above setValue(...). If you look at this method,
@Override
public Object getValue() {
return isLocalValueSet() ? getLocalValue() : super.getValue();
}
If the local value was set by setValue(...), indicated by the flag setLocalValueSet(true)
,
why is this returning the getLocalValue()?
I mean,
isLocalValueSet() ? getLocalValue() : ....
Why is it not
isLocalValueSet() ? getValue() : ....
As seen through above, my confusion is regarding getValue()
& getLocalValue()
methods. Furthermore, in which case Object previous = getValue();
will be not null
?