5

複合コンポーネントを作成しています。次の名前の特別なタグがあります。

<composite:insertChildren />

これにより、すべてのコンポーネントの子がそこに挿入されます。コンポーネントに子があるかどうかを知る方法はありますか?「rendered」属性に使用できるブール値のように。

4

3 に答える 3

7

あなたが求めている基本的な表現は次のとおりです。

#{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で使用されます。

<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}、複合コンポーネントに子があるかどうかがわかります。

于 2011-02-13T08:39:21.110 に答える
6

同じ問題が発生し、ファセット'javax.faces.component.COMPOSITE_FACET_NAME'内で複合コンポーネントの子を見つけることができました。

Javaでは次のようになります。

// we are within some method of UIComponent
UIComponent childrenHolderFacet = getFacets().get("javax.faces.component.COMPOSITE_FACET_NAME");
Iterator<UIComponent> childrenIt = childrenHolderFacet.getChildren().iterator();
...

JSFでは次のようなものです。

#{component.getFacets().get("javax.faces.component.COMPOSITE_FACET_NAME").children}

それが役に立てば幸い。

于 2011-06-03T06:39:48.103 に答える
2

少なくともMojarraでは、これは機能しません。複合コンポーネントの子は問題なく挿入されますが、2.0.2にアクセスする#{cc.parent}か、動作せず、子の数に関係なく、常に2.0.4に戻ります。#{cc.children}#{cc.childCount}0

于 2011-03-01T11:00:49.823 に答える