Composite component validation in JSF 2.0

左心房为你撑大大i 提交于 2019-12-12 20:02:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!