I do not understand the behaviour of JSF2 during valdation. Hope someone can help me.
I have a form where the fields are validated after (ajax) submit - ok
Had a similar issue where a value loaded in from the backing bean would get reset when the field was blanked out and another component failed validation. I had to make a slight addition to BalusC's code to make it work.
protected String getCurrentValue(FacesContext context,
UIComponent component) {
if (component instanceof UIInput && !((UIInput) component).isValid()) {
Object submittedValue = ((UIInput) component).getSubmittedValue();
if (submittedValue != null) {
// value may not be a String...
return submittedValue.toString();
} else {
return null;
}
}
String currentValue = null;
Object currentObj;
if ( component instanceof UIInput && ((UIInput)component).isLocalValueSet() )
{
currentObj = ((UIInput)component).getLocalValue();
}
else {
currentObj = getValue(component);
}
if (currentObj != null) {
currentValue = getFormattedValue(context, component, currentObj);
}
return currentValue;
}