1

次のようなカスタムコンポーネントがあります

<custom:container>
    <custom:checkbox index="0"/>
    <custom:checkbox index="1"/>
</custom:container>

したがって、encodeBegin が最初に呼び出されると、タグが表示<custom:container>され、このコンポーネントのクライアント ID を保存しようとします。

private String containerClientId;
public void encodeBegin(FacesContext context, UIComponent component){
    if (component instanceof ManyCheckboxContainer) {            
        containerClientId = component.getClientId(context);
        return; 
    }
}

<custom:checkbox index="0"/>だから、このように、私がヒットしたときにencodeEndが呼び出されます

public void encodeEnd(FacesContext context, UIComponent component) throws IOException {

    ...

    if (component instanceof Checkbox) {
        renderCheckbox(context, (Checkbox) component);
    } 
    ...
}

protected void renderCheckbox(FacesContext facesContext, InforRadio radio) throws IOException {
    ...
    UIComponent uiComponent = radio.findComponent(containerClientId);
    if(uiComponent == null){
         //throw error
    }
    ...
}

複合コンポーネント内にこのカスタム コンポーネントがない場合は、すべて正常に機能しますが、複合コンポーネントに配置するとradio.findComponent(containerClientId);null. これはモハラのバグですか?これを 2.1.10 と 2.1.11 でテストしましたが、同じ動作です。

編集
それを元に戻します。この動作は、カスタムコンポーネントが2つのネストされた内部にある場合に発生するNamingContainerため、次のようなものです

<h:form id="myForm">
    <f:subView id="myView">
        <custom:container id="myCustom">
            <custom:checkbox index="0"/>
            <custom:checkbox index="1"/>
        </custom:container>
    </f:subView>
</h:form>

したがって、この場合、クライアントID(によって返されるcomponent.getClientId(context))は<custom:container>ですがmyForm:myView:myCustom、Mojarra内では、findComponentメソッドにはこれがあります

public UIComponent findComponent(String expr) {
     ...

     else if (!(base instanceof NamingContainer)) {
     // Relative expressions start at the closest NamingContainer or root
     while (base.getParent() != null) {
         if (base instanceof NamingContainer) {
             break;
         }
         base = base.getParent();
     }
     ...
}

そのため、次の祖先を探します。NamingContainerこれは、私の場合は ではありf:subViewませんh:form。次に、クライアント ID を解析し、ID の一部を に渡すたびにループしますUIComponent findComponent(UIComponent base, String id, boolean checkId)。したがって、初めて、このメソッドは id として取得され、現在の UIComponent は f: subViewであり、すべてのファセットと子を検索して、form3一致するコンポーネントがあるかどうかを確認します。リターンも同様です。これは Mojarra のバグですか、それとも私が間違っているのでしょうか。クライアント ID は、NamingContainer のルートまでではなく、次の NamingContainer の祖先から相対的だと思いましたか? 私はそれについて間違っていますか?form3form3f:subViewnull

4

1 に答える 1

3

ドキュメントを読んだ後、Mojarraがそれを正しく理解したように私には思えます。

ドキュメントによると、ツリーのルートから「絶対」検索を実行する場合は、検索式の前に区切り文字(コロン)を配置する必要があります。それ以外の場合、コンポーネントがNamingContainerであるか、NamingContainerである最初の親である場合は、コンポーネント自体から相対検索を実行します。

ところで:私がリンクしたドキュメントは、仕様とともに配布された公式ドキュメントと同じように見えます。公式スペックはこちらです。

于 2012-08-10T06:45:10.470 に答える