我使用<rich:datatable>
來顯示來自List<Map<String, String>>
(實際上,該列表只有一個Map<String, String>
)的數據。 datatable
在一行中顯示數據,並顯示該行旁邊的編輯和刪除按鈕。刷新一些內容以使它們在單擊刪除按鈕後消失
當我單擊delete button
時,我清除了List
和數據庫中的寄存器。我想單擊delete button
時,不要顯示datatable
中的內容並禁用edit
和delete
buttons
。這裏的數據表代碼:
<rich:dataTable value="#{searchAuthDetailController.finalResults}"
id="table" var="result">
<c:forEach items="#{searchAuthDetailController.variableNames}" var="vname">
<rich:column>
<f:facet name="header">#{vname}</f:facet>
#{result[vname]}
</rich:column>
</c:forEach>
<rich:column>
<h:commandButton action="EditAuthor" value="Edit"
disabled="#{searchAuthDetailController.editBtDisabled}">
<f:setPropertyActionListener target="#{editAuthController.selectedAuthor}"
value="#{searchAuthDetailController.selectedAuthor}"/>
</h:commandButton>
</rich:column>
<rich:column>
<a4j:commandButton value="Delete" disabled="#{searchAuthDetailController.deleteBtDisabled}"
action="#{searchAuthDetailController.removeSelectedAuthor()}" render="table"/>
</rich:column>
</rich:dataTable>
也有一個List<String>
顯示datatable
下面的一些鏈接。我希望這些鏈接和上面的文本不會再出現,點擊刪除按鈕後。
<h:outputText value="#{searchAuthDetailController.linksLabel}" />
<br />
<a4j:repeat value="#{searchAuthDetailController.sameasListToShow}" var="uri" >
<a href="#{uri}">#{uri}</a>
<br />
</a4j:repeat>
我用2個變量稱爲deleteBtDisabled
和editBtDisabled
從disabled property
從按鈕的值。在刪除()(下面的代碼)我將這些變量設置爲true
,我清除List<Map<String, String>>
,變量名List
,List
鏈接顯示和linkslabel
。 這裏的remove()
:
public void removeSelectedAuthor() {
this.authMapper.remove(bdModel, this.selectedAuthor);
this.variableNames.clear();
this.editBtDisabled = true;
this.deleteBtDisabled = true;
this.sameasListToShow.clear();
this.linksLabel = "";
}
此外,delete button
有render
屬性設置爲datatable's
ID。
有了所有這些代碼,當我單擊刪除按鈕時,只有來自數據表的內容消失,但按鈕繼續啓用,並且鏈接列表在那裏繼續。
我該如何解決這個問題?
謝謝!你能給我一個例子和一個數據表(不需要richfaces一個)。我不知道如何使用它.. –
Luciane
我更新了我的答案。我在Tomcat 7.x上使用JSF 2.2,Mojarra 2.2對其進行了測試。 –
謝謝你的例子!這是我使用的確切配置。查看f:ajax的執行和渲染屬性。我使用標籤的名稱? - 您是否使用@form,因爲h:form標籤? – Luciane