4

データテーブル内のコンポーネントのクライアントIDを取得しようとしています。問題は、jsfがコンポーネントIDの前に行インデックスを自動的に配置することです。

   <a id="mappedidentifier_table:1:mappedidentifier_Update" href="#">Update</a>

2行目のリンクの場合(インデックス= 1)。

次のメソッドを使用してclientIdを取得しています

   public static String findClientId(String id) {
        FacesContext context = FacesContext.getCurrentInstance();
        UIViewRoot view = context.getViewRoot();
        if (view == null) {
            throw new IllegalStateException("view == null");
        }
        UIComponent component = findComponent(view, id);
        if (component == null) {
            throw new IllegalStateException("no component has id='" + id + "'");
        }
        return component.getClientId(context);
    }

    private static UIComponent findComponent(UIComponent component, String id) {
        if (id.equals(component.getId())) {
            return component;
        }

        Iterator<UIComponent> kids = component.getFacetsAndChildren();
        while (kids.hasNext()) {
            UIComponent kid = kids.next();
            UIComponent found = findComponent(kid, id);
            if (found != null) {
                return found;
            }
        }

        return null;
    }

ただし、これは

mappedidentifier_table:mappedidentifier_Update

それ以外の

mappedidentifier_table:1:mappedidentifier_Update

したがって、どの要素とも一致しないため、idの行インデックスが欠落しています。

http://illegalargumentexception.blogspot.com/2009/05/jsf-using-component-ids-in-data-table.htmlを読みました

ただし、作成者のようにTLD関数やフェイスレットではなく、より単純な実装にするつもりです。

誰か考えがありますか?

ありがとう、

dzh

4

1 に答える 1

3

ただし、これはmappedidentifier_table:mappedidentifier_Update代わりに戻りますmappedidentifier_table:1:mappedidentifier_Update

clientIdこれは、行のコンテキストの外側を解決する場合に発生します。行コンテキストは、コントロールによってライフサイクルの各段階で設定されますUIData

EL式で遅延評価の代わりに即時評価を使用している場合にも発生する可能性があります-${}の代わりに#{}

余談ですが、記事に記載されているように、そのルックアップアルゴリズムは、コンポーネント識別子がビューに一意である場合にのみ機能します。NamingContainer仕様によると、それは;に固有である必要があるだけです。ページで一意のコンポーネントIDを使用することに注意する場合、これは問題になる必要はありません。

于 2009-10-01T14:31:05.913 に答える