After OmniFaces <o:validateMultiple>
validation, <p:inputText>
values are lost.
I can reporduce problem then web.xml contains parameter javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
:
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
If I remove this parameter - everything works fine.
I have JSF view:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui">
<h:form id="someForm">
<div>
<o:outputLabel for="bar1" value="Bar1" />
<p:inputText id="bar1" />
<p:message for="bar1"/>
</div>
<div>
<o:outputLabel for="bar2" value="Bar2" />
<p:inputText id="bar2" />
<p:message for="bar2"/>
</div>
<div>
<o:outputLabel for="bar3" value="Bar3" />
<h:inputText id="bar3" />
<h:message for="bar3"/>
</div>
<div>
<o:outputLabel for="bar4" value="Bar4" />
<h:inputText id="bar4" />
<h:message for="bar4"/>
</div>
<o:validateMultiple components="bar1 bar2 bar3 bar4"
validator="#{sameValueValidator}"
message="All values shold be the same"
showMessageFor="bar2 bar4"/>
<p:commandButton value="submit" process="@form" update="@form" />
</h:form>
</html>
and validator:
public class SameValueValidator implements MultiFieldValidator {
@Override
public boolean validateValues(FacesContext context,
List<UIInput> components, List<Object> values) {
if (!values.isEmpty()) {
Object firstValue = values.get(0);
for (Object value : values) {
if (!Objects.equal(firstValue, value)) {
return false;
}
}
return true;
} else {
return false;
}
}
}
If <o:validateMultiple>
validation fails (texts in <p:inputText>
components are not the same) <p:inputText id="bar1">
and <p:inputText id="bar2">
become empty, but <h:inputText id="bar3">
and <h:inputText id="bar4">
keep values.
I think <p:inputText>
should not lose values or am I doing something wrong?
I am using,
- PrimeFaces 5.1.14 (or 5.2.RC2)
- OmniFaces 1.8.1
- Mojarra 2.2.10
- Tomcat 8
- Java 8
<o:validateEqual>
for the very purpose of validating multiple components on equality. – BalusC