You need to specify the for attribute of the validator so that it matches name <composite:editableValueHolder> .
<xxx:inputText value="..."> <f:validateLength for="myinput" minimum="10" /> </xxx:inputText>
You also need to make sure that <composite:editableValueHolder> is specified in both composites, as well as input.xhtml . Here is a complete example that works great for me on Mojarra 2.1.12:
/resources/components/input.xhtml :
<ui:component xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:cc="http://java.sun.com/jsf/composite" > <cc:interface> <cc:attribute name="label" required="true" /> <cc:editableValueHolder name="input" targets="input" /> </cc:interface> <cc:implementation> <h:outputLabel for="input" value="#{cc.attrs.label}" /> <cc:insertChildren /> </cc:implementation> </ui:component>
/resources/components/inputText.xhtml :
<ui:component xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:my="http://java.sun.com/jsf/composite/components" > <cc:interface> <cc:attribute name="label" required="true" /> <cc:attribute name="value" required="true" /> <cc:editableValueHolder name="input" targets="input:text" /> </cc:interface> <cc:implementation> <my:input id="input" label="#{cc.attrs.label}"> <h:inputText id="text" value="#{cc.attrs.value}" /> </my:input> </cc:implementation> </ui:component>
Usage in some test.xhtml :
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:my="http://java.sun.com/jsf/composite/components" > <h:head> <title>SO question 12188638</title> </h:head> <h:body> <h:form> <my:inputText label="foo" value="#{bean.input}"> <f:validateLength minimum="10" for="input" /> </my:inputText> <h:commandButton value="submit" action="#{bean.submit}"> <f:ajax execute="@form" render="@form"/> </h:commandButton> <h:messages/> </h:form> </h:body> </html>
See also:
Unrelated to a specific problem, do you know about <h:outputLabel> ?
<h:outputLabel value="#{cc.attrs.labelText}" />
And the fact that you can simply insert EL into the template text without the explicit need for <h:outputText> ?
<label>
Did you notice that your label also lacks the for attribute, which should refer to the identifier of the input element that the label should refer to?
<h:outputLabel for="someId" ... /> <h:inputText id="someId" ... />
Balusc
source share