I want to create validator for composite component where I want to pass few attributes. This is how code looks like (it's not original code but is implemented in the same way):
Composite component (compositeComponent.xhtml)
<h:body>
<composite:interface componentType="compositeComponent">
<composite:attribute name="name" required="true" />
<composite:attribute name="value" required="true" />
<composite:attribute name="values" required="true" />
<composite:editableValueHolder name="validator" targets="#{cc.attrs.id}"/>
</composite:interface>
<composite:implementation>
<h:selectOneMenu value="#{cc.attrs.value}" id="#{cc.attrs.id}">
<f:selectItems value="#{cc.attrs.values}" var="item" itemValue="#{item.value}" itemLabel="#{item.label}" />
<composite:insertChildren/>
</h:selectOneMenu>
</composite:implementation>
</h:body>
As you can see I want to pass validator to h:selectOneMenu
. Composite component can be (to be more precisely 'should be' because it currently doesn't work) used in this way:
<ns:compositeComponent name="myComp" value="#{controller.value}" values="#{controller.values}">
<f:validator validatorId="myValidator" for="validator">
<f:attribute name="param1" value="param1Value"/>
<f:attribute name="param1" value="param1Value"/>
</validator>
</ns:compositeComponent>
I tested this code and validator is called if i don't pass attributes into it.
<ns:compositeComponent name="myComp" value="#{controller.value}" values="#{controller.values}">
<f:validator validatorId="myValidator" for="validator"/>
</ns:compositeComponent>
I found that attributes can be passed in this way:
<ns:compositeComponent name="myComp" value="#{controller.value}" values="#{controller.values}">
<f:validator validatorId="myValidator" for="validator"/>
<f:attribute name="param1" value="param1Value"/>
<f:attribute name="param1" value="param1Value"/>
</ns:compositeComponent>
but (as far as I know) only validator will be injected to custom component (thats why for="validator"
is set on validator) so I won't be able to get these attributes. How can I pass attributes to this validator?
BTW. If it's possible I will want to pass parameters as nested elements because it looks more clear. This one:
<f:selectOneMenu>
<f:validator validatorId="myValidator">
<f:attribute name="param1" value="value1"/>
</f:validator>
</f:selectOneMenu>
instead of this one:
<f:selectOneMenu>
<f:validator validatorId="myValidator"/>
<f:attribute name="param1" value="value1"/>
</f:selectOneMenu>