我目前有2個命令按鈕和一個列表框。根據列表框的選擇,生成的結果可以顯示在可下載的文件中或呈現爲HTML表格。 getFile()
代碼基於BalusC's PDF Handling tutorial,而getTable()
集合resultTable
。h:commandButton多個動作:下載文件並渲染ajax表
<h:form>
<fieldset>
<h:selectManyListbox id="listbox" value="#{form.items}">
<f:selectItems value="#{form.allItems}">
</h:selectManyListbox>
</fieldset>
<h:commandButton value="Get File" action="#{form.getFile}">
<h:commandButton value="Get Table" action="#{form.getTable}">
<f:ajax render="result_table" execute="listbox" />
</h:commandButton>
<h:panelGrid id="result_table">
<table>
<thead></thead>
<tbody>
<ui:repeat var="table" value="#{form.resultTable}">
</ui:repeat>
</tbody>
</table>
</h:panelGrid>
到目前爲止,兩個按鈕都工作正常。但是,我想將這兩個操作合併到一個按鈕中。當我用一個觸發兩個動作的按鈕來測試時,沒有任何反應(沒有文件保存爲對話框或表格呈現)。這是因爲一個動作是ajax還是因爲其他動作完成了facesContext.responseComplete();
?
<h:commandButton value="Get Both" action="#{form.getBoth}">
<f:ajax render="result_table" execute="listbox" />
</h:commandButton>
getBoth() {
getTable();
getFile();
}
此外,我想要一個複選框,如果它被選中,另存爲彈出對話框和表格呈現。如果未選中,則只顯示錶格。
感謝您的解釋。我將繼續使用這兩個按鈕。 – luciaengel 2010-11-29 13:48:49