JSF2复合组件:#{cc.childCount}和< composite:insertChildren/>互斥? [英] JSF2 composite components: are #{cc.childCount} and <composite:insertChildren/> mutually exclusive?

查看:73
本文介绍了JSF2复合组件:#{cc.childCount}和< composite:insertChildren/>互斥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是不明白: 如果我想在复合组件中插入子代,我使用 <composite:insertChildren/>,但在这种情况下,#{cc.childCount}始终返回0.另一方面,如果我不使用 <composite:insertChildren/>,我总是会得到正确的childCount,而不会渲染任何子级.为什么会这样?

I just dont get it: If I want my composite component to insert children, I use <composite:insertChildren/> but #{cc.childCount} always returns 0 in that case. On the other hand, If I do not use <composite:insertChildren/> I always get correct childCount without children being rendered. Why is that happening?

我要在组件中做的就是在没有子级的情况下呈现一些默认"面板,在其他情况下不呈现它-类似于<ui:insert name="param_name">default value</ui:insert>的行为.因此,我需要insertChildren和childCount似乎都不能一起工作.

All I want to do in my component is to render some "default" panel if there are no children and do not render it in other case - behavior similar to <ui:insert name="param_name">default value</ui:insert>. So I need both insertChildren and childCount which do not seem to work together.

这是代码:

<my:test>
  <h:outputText value="child1" rendered="#{some.trueValue}"/>
  <h:outputText value="child2" rendered="#{some.trueValue}"/>
<my:test>

如果我在下面使用实现,则会按预期方式呈现2

If I use implementation below, I get 2 rendered as expected

<composite:implementation>
  <h:outputText value="#{cc.childCount}"/> 
</composite:implementation>

使用insertChildren时,将同时渲染两个子级,并同时显示0:

When insertChildren is used I get both children rendered and 0 at the end:

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

有什么想法/解决方法吗?

Any ideas/workarounds?

推荐答案

将子级放入具有id的panelGroup中(例如,子级).

Put the children in a panelGroup with an id (eg children).

然后

#{component.findComponent('children').childCount}

将为您提供正确的值.祝你好运!

will give you the correct value. Good luck!

这篇关于JSF2复合组件:#{cc.childCount}和&lt; composite:insertChildren/&gt;互斥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆