4

richfaces extendedDataTable を a4j:support で使用して、rich:panel の「レンダリング」属性の値を変更しようとしていますが、機能していません。

これは、rich:extendedDataTable と rich:panel を含む私の JSF ページの一部です。

<h:form id="tabForm">
<rich:extendedDataTable id="myTable" width="500px" height="250px"
value="#{extDataTableBean.extList}" var="dataRow"
selection="#{extDataTableBean.selection}" selectionMode="single">
    <rich:column>
        <f:facet name="header"><h:outputText value="ID" /></f:facet>
        <h:outputText value="#{dataRow.id}"></h:outputText>
    </rich:column>
    <rich:column>
        <f:facet name="header"><h:outputText value="Name" /></f:facet>
        <h:outputText value="#{dataRow.name}"></h:outputText>
    </rich:column>
    <a4j:support id="myTableTakeSelection" action="#{extDataTableBean.takeSelection}" event="onselectionchange" reRender="pane" />
</rich:extendedDataTable>
</h:form>
<rich:panel id="pane" rendered="#{extDataTableBean.showPane}">
<h:form id="secForm">
    <h:outputText value="ID : " />
    <h:inputText id="inTextID"  value="#{extDataTableBean.idFd}" />
    <br/>
    <h:outputText value="Name : " />
    <h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
</h:form>
</rich:panel>

rich:panel 'rendered' 属性のデフォルト値は false (バッキング Bean で設定) です。私が達成したかったのは、extendedDataTable の行が選択されたときに、その値が true に変更されて GUI に表示されるようにすることです。

そして、これは私のバッキング Bean の一部です。

/* Constructor */
public ExtDataTableBean(){
    setShowPane(false); // default to false
    loadDataList();
}

/* Load some test data into extendedDataTable */
public void loadDataList(){
    extList = new ArrayList<MyData>();
    MyData e1 = new MyData();
    e1.setId(1);
    e1.setName("name 1");
    extList.add(e1);
    MyData e2 = new MyData();
    e2.setId(2);
    e2.setName("name 2");
    extList.add(e2);
}

public String takeSelection(){
    Iterator iterator = getSelection().getKeys();
    Object key = null;
    while(iterator.hasNext()){
        key = iterator.next();
    }
    /* set the values of inputText with value from selected row */
    setIdFd(extList.get(Integer.parseInt(key.toString())).getId());
    setNameFd(extList.get(Integer.parseInt(key.toString())).getName());
    setShowPane(true);
    return null;
}

public List<MyData> getExtList() {
            /* Lazy loading */
    if(extList == null){
        loadDataList();
    }
    return extList;
}

takeSelection( ) メソッドで setShowPane(true) を使用して、rich:panel 'rendered' 属性の値を true に変更しました。問題は豊富です。行が選択されているときにパネルが GUI に表示されません。

次のように、a4j:support を指定して ah:commandButton を追加し、showPane を true に設定して、別の簡単なテストを行いました。

<h:commandButton id="cmdBtn" value="Show Pane">
    <a4j:support id="cmdBtnSupport" reRender="pane" action="#{extDataTableBean.dispPane}" event="onclick" />
</h:commandButton>

バッキング Bean では次のようになります。

public String dispPane(){
    setShowPane(true);
    return null;
}

期待どおりに動作しています。ボタンをクリックすると、rich:panel が GUI に表示されます。

私のコードで何が欠けていましたか?

4

2 に答える 2

3

このWebサイトから問題の原因を見つけたと思います:http: //community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering

問題を説明した部分の抜粋:

クライアント側の更新:

フレームワークは以前はDOMになかった要素をどこに追加するかわからないため、reRender属性は条件付きでレンダリングされた要素を指すべきではありません。そのようなコンポーネントの親は、代わりに再レンダリングする必要があります。

したがって、再レンダリングするようにパーツを変更し、バインディングを次のようにレンダリングした後、現在は機能しています。

<rich:panel id="pane" >
    <h:form id="secForm" rendered="#{extDataTableBean.showPane}" >
        <h:outputText value="ID : " />
        <h:inputText id="inTextID"  value="#{extDataTableBean.idFd}" />
        <br/>
        <h:outputText value="Name : " />
        <h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
    </h:form>
</rich:panel>
于 2010-10-26T09:19:00.700 に答える
0

<rich:extendedDataTable>すぐに使用できる Ajax 対応です。<a4j:support>などの非 ajax JSF コンポーネントに ajax 機能をもたらすことを目的としたタグを追加する必要はありません<h:inputText>

したがって、代わりにこれを試してください:

<rich:extendedDataTable onselectionchange="#{extDataTableBean.takeSelection}">

幸運を。

于 2010-10-25T16:17:19.603 に答える