本文介绍了在JSF2中,如何知道复合组件是否有子级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个复合组件,您有一个特殊的标签,名为:
I'm writing a composite component, you have a special tag named:
<composite:insertChildren />
将所有组件子级插入那里.有什么办法可以知道组件是否有子级?就像布尔值一样,可以使用"rendered"属性.
Which inserts all the component's children there. Is there any way to know whether the component has children? Like a boolean value that could go on a "rendered" attribute.
推荐答案
您要遵循的基本表达式如下:
The basic expression you're after is the following:
#{cc.childCount}
或更详细地讲:
#{component.getCompositeComponentParent(component).childCount}
例如以下复合组件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite"
>
<cc:interface/>
<cc:implementation>
<h:outputText value="Children: #{cc.childCount}" />
</cc:implementation>
</html>
用于以下Facelet:
used on the following Facelet:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:test="http://java.sun.com/jsf/composite/test"
>
<h:body>
<test:myCom>
<h:outputText value="first child" />
<h:outputText value="second child" />
</test:myCom>
</h:body>
</html>
将打印Children: 2
.
因此,#{cc.childCount != 0}
将告诉您复合组件是否具有子组件.
Thus #{cc.childCount != 0}
will tell you whether a composite component has children or not.
这篇关于在JSF2中,如何知道复合组件是否有子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!