问题
I have composite component in JSF 2.0
<composite:interface>
<composite:attribute name="inputId"/>
<composite:attribute name="labelValue"/>
<composite:attribute name="inputValue" />
<composite:attribute name="required" />
<composite:attribute name="requiredMessage" />
</composite:interface>
<composite:implementation>
<div class="control-group">
<h:outputLabel for="#{cc.attrs.inputId}" value="#{cc.attrs.labelValue}" class="control-label" />
<div class="controls">
<h:inputText id="#{cc.attrs.inputId}" value="#{cc.attrs.inputValue}" required="#{cc.attrs.required}" requiredMessage="#{cc.attrs.requiredMessage}" />
</div>
</div>
</composite:implementation>
and I need to make some validation on it (is it number, lenght validation etc) So, how can I make it?
回答1:
You need to define the desired input for which you'd like to attach a validator as a <cc:editableValueHolder> in the <cc:interface>
.
<cc:interface>
<cc:editableValueHolder name="input" targets="#{cc.attrs.inputId}" />
...
</cc:interface>
The tag basically tells that any <f:validator for="input">
must be applied on the UIInput
component with the same id
as specified in targets
. So, you can then register it as follows:
<my:input ...>
<f:validateLength for="input" ... />
</my:input>
来源:https://stackoverflow.com/questions/10873948/composite-component-validation-in-jsf-2-0