我只是不明白:
如果我想让我的复合组件插入子组件,我 使用 <composite:insertChildren/>
但是 #{cc.childCount}
总是返回 0
在这种情况下。另一方面,如果我 不要使用 <composite:insertChildren/>
我总是得到正确的 childCount
没有 child 被渲染。为什么会这样?
我想要在我的组件中做的就是在没有 child 的情况下呈现一些“默认”面板,并且在其他情况下不呈现它 - 行为类似于 <ui:insert name="param_name">default value</ui:insert>
.所以我需要 insertChildren 和 childCount 这两个似乎不能一起工作的。
这是代码:
<my:test>
<h:outputText value="child1" rendered="#{some.trueValue}"/>
<h:outputText value="child2" rendered="#{some.trueValue}"/>
<my:test>
如果我使用下面的实现,我会得到
2
按预期呈现<composite:implementation>
<h:outputText value="#{cc.childCount}"/>
</composite:implementation>
当
insertChildren
使用我得到两个 child 渲染和 0
在末尾:<composite:implementation>
<composite:insertChildren/>
<h:outputText value="#{cc.childCount}"/>
</composite:implementation>
而我的目标是:
<composite:implementation>
<composite:insertChildren/>
<h:panelGroup rendered="#{cc.childCount == 0}">
some default data
</h:panelGroup>
</composite:implementation>
任何想法/解决方法?
最佳答案
将 child 放在一个带有 id 的 panelGroup 中(例如 child )。
然后
#{component.findComponent('children').childCount}
会给你正确的值。祝你好运!
关于JSF2 复合组件 : are #{cc. childCount} 和 <composite :insertChildren/> mutually exclusive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377542/