I would like to mark a single component within ui:repeat
as not valid. My attempt:
Bean:
@Named
@RequestScoped
public class TestBean {
private List<String> strLst;
@PostConstruct
public void init() {
strLst = Arrays.asList("a", "b", "c");
}
public String send() {
return null;
}
public List<String> getStrLst() {
return strLst;
}
}
Validator:
@FacesValidator(value = "TestValidator", managed = true)
public class TestValidator implements Validator<String> {
@Override
public void validate(FacesContext arg0, UIComponent comp, String foo) throws ValidatorException {
throw new ValidatorException(new FacesMessage("Error"));
}
}
Facelet:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form>
<h:messages />
<!-- After validation error component keeps in state 'valid' - wrong! -->
<ui:repeat var="str" value="#{testBean.strLst}">
<h:inputText value="#{str}" validator="TestValidator"
styleClass="#{component.valid ? 'foo' : 'error'}" />
</ui:repeat>
<!-- After validation error the component switches in state 'not valid' - correct! -->
<h:dataTable var="str" value="#{testBean.strLst}">
<h:column>
<h:inputText value="#{str}" validator="TestValidator"
styleClass="#{component.valid ? 'foo' : 'error'}" />
</h:column>
</h:dataTable>
<h:commandButton action="#{testBean.send}" value="Send" />
</h:form>
</h:body>
</html>
My problem: The component in ui:repeat
keeps in state valid
, so the styleClass error
is not set. With h:dataTable
no such problems. But I need a horizontal list, so h:dataTable
is not an option here.
Also not working with Omnifaces 1.14.1 as described in https://stackoverflow.com/a/9195360/802058:
<ui:repeat var="str" value="#{testBean.strLst}">
<h:inputText value="#{str}" styleClass="#{component.valid ? 'foo' : 'error'}">
<o:validator validatorId="TestValidator" />
</h:inputText>
</ui:repeat>
Is this a bug or a feature?
Mojarra 2.3.9.SP01