【问题标题】:f:selectItem inside of a composite componentf:selectItem 在复合组件内
【发布时间】:2011-10-07 14:32:55
【问题描述】:

我正在尝试使用复合组件创建自己的 selectManyCheckbox。但是当我尝试使用自己的 selectItem 组件时,项目不会被渲染。

selectItem.xhtml:

<cc:implementation>

    <f:selectItem rendered="true" id="#{cc.attrs.id}"
        itemDescription="#{cc.attrs.itemDescription}"
        itemDisabled="#{cc.attrs.itemDisabled}"
        itemLabel="#{cc.attrs.itemLabel}" itemValue="#{cc.attrs.itemValue}"
        value="#{cc.attrs.value}">

    </f:selectItem>

</cc:implementation>

selectManyCheckbox.xhtml:

 <!--Some other stuff like label -->
 <h:selectManyCheckbox styleClass="#{cc.attrs.styleClass}"
                id="#{cc.attrs.id}_checkbox" value="#{cc.attrs.value}"
                layout="pageDirection">

                <cc:insertChildren />
</h:selectManyCheckbox>

当我使用时

 <mycomps:selectManyCheckbox id="abc" labelString="Example">
                <mycomps:selectItem itemValue="1" itemLabel="One" />
            </mycomps:selectManyCheckbox>

它不起作用。但是当我使用

<mycomps:selectManyCheckbox id="abc" labelString="Example">
                <f:selectItem itemValue="1" itemLabel="One" />
            </mycomps:selectManyCheckbox>

确实如此!有人知道我该如何解决这个问题吗?

谢谢!

【问题讨论】:

  • 我看不到将&lt;f:selectItem&gt; 1:1 包装在这样的复合组件中的意义。这里究竟增强了什么?
  • 我只是省略了其他代码

标签: jsf checkbox jsf-2 composite-component


【解决方案1】:

我通过将componentType="javax.faces.SelectItrm" 属性/值添加到`cc:interface 元素来解决它。试试这样:

<cc:interface componentType="javax.faces.SelectItem">
...
</cc:interface>
<cc:implementation>

    <f:selectItem rendered="true" id="#{cc.attrs.id}"
        itemDescription="#{cc.attrs.itemDescription}"
        itemDisabled="#{cc.attrs.itemDisabled}"
        itemLabel="#{cc.attrs.itemLabel}" itemValue="#{cc.attrs.itemValue}"
        value="#{cc.attrs.value}">

    </f:selectItem>

</cc:implementation>

【讨论】:

  • 拥有这样的 1:1 组件有什么好处?
猜你喜欢
  • 2017-02-13
  • 2014-06-24
  • 2011-12-19
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
  • 2012-06-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多