【问题标题】:Composite component validation in JSF 2.0JSF 2.0 中的复合组件验证
【发布时间】:2012-06-08 02:12:23
【问题描述】:

我在 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>

我需要对其进行一些验证(是数字、长度验证等) 那么,我该怎么做呢?

【问题讨论】:

    标签: validation jsf-2 facelets composite-component


    【解决方案1】:

    您需要在&lt;cc:interface&gt; 中定义要为其附加验证器的所需输入作为&lt;cc:editableValueHolder&gt;。

    <cc:interface>
        <cc:editableValueHolder name="input" targets="#{cc.attrs.inputId}" />
        ...
    </cc:interface>
    

    该标签基本上告诉任何&lt;f:validator for="input"&gt; 必须应用在UIInput 组件上,并具有与targets 中指定的相同的id。因此,您可以按如下方式注册它:

    <my:input ...>
        <f:validateLength for="input" ... />
    </my:input>
    

    【讨论】:

      猜你喜欢
      • 2011-05-19
      • 2012-01-30
      • 2011-11-09
      • 2013-02-02
      • 2011-04-16
      • 2012-04-01
      • 2013-10-17
      • 2012-02-23
      • 1970-01-01
      相关资源
      最近更新 更多