Primefaces:confirmDialog中的commandButton无法以相同形式更新数据表 [英] Primefaces: commandButton in confirmDialog cannot update datatable in the same form
问题描述
我有1个数据表,其中每行都包含编辑"和删除"命令按钮.删除按钮显示一个单击确认对话框,并由actionListener将currentObject变量设置为它在同一行中所属的对象.
I have 1 datatable which includes Edit and Delete command buttons in each row. Delete button shows a confirm dialog onclick, and by actionListener, sets the currentObject variable to the object that it belongs to in the same row.
在确认对话框中,是"也是一个命令按钮,它调用bean的delete(object)方法.
In the confirm dialog, Yes is also a command button, and it calls delete(object) method of the bean.
一切正常.删除功能如下:
Everything works fine. Delete function is below:
public void delete(ActionEvent actionEvent) {
categoryRepository.delete(currentCategory);
currentCategory = new Category();
categoryList = categoryRepository.findAll();
}
我要在删除后更新数据表.但是更新不适用于数据表.我只能更新@form,但是这次,页面中的所有内容都被禁用,并且我无法选择任何内容.可能是个错误.
I want to update the datatable after delete. But update does not work for datatable. I can only update @form, but this time, everything in the page becomes disable, and I cannot select anything. Can be a bug.
这是xhtml代码:
<h:form id="categoryForm">
<p:commandButton id="addCategoryButton" value="New"
onclick="categoryDialog.show();" type="button" />
<p:dataTable var="cat" value="#{categoryBean.categoryList}"
rowKey="#{cat.id}" paginator="true" rows="10"
selection="#{categoryBean.selectedCategories}" id="categoryTable"
widgetVar="categoryTable">
<f:facet name="header">
Category List
</f:facet>
<p:column selectionMode="multiple" />
<p:column headerText="Name" sortBy="#{cat.name}"
filterBy="#{cat.name}" id="name">
#{cat.name[categoryBean.currentLocale.language]}
</p:column>
<p:column headerText="Sort Order" sortBy="#{cat.sortOrder}"
filterBy="#{cat.sortOrder}" id="sortOrder">
#{cat.sortOrder}
</p:column>
<p:column headerText="Actions" id="actions">
<h:commandButton action="#{categoryBean.edit(cat)}" value="Edit" />
<h:commandButton value="Delete"
onclick="deleteConfirmation.show()" type="button">
<f:setPropertyActionListener value="#{cat}"
target="#{categoryBean.currentCategory}" />
</h:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog id="deleteConfirmDialog" message="Are you sure?"
header="Initiating destroy process" severity="alert"
widgetVar="deleteConfirmation">
<p:commandButton id="confirm" value="Yes Sure"
update=":categoryForm:categoryTable"
oncomplete="deleteConfirmation.hide()"
actionListener="#{categoryBean.delete}" />
<p:commandButton id="decline" value="Not Yet"
onclick="deleteConfirmation.hide()" type="button" />
</p:confirmDialog>
<p:dialog id="categoryDialog" header="Category Detail"
widgetVar="categoryDialog" resizable="false" style="width:90%;"
showEffect="explode" hideEffect="explode">
<p:panel id="panel" header="Edit Category"
style="margin-bottom:10px;">
<p:messages id="messages" />
<h:panelGrid columns="3">
<h:outputLabel for="nameTabView" value="Name: " />
<p:tabView id="nameTabView">
<c:forEach var="locale" items="#{categoryBean.userLocales}">
<p:tab title="#{locale.displayLanguage}">
<h:panelGrid columns="2" cellpadding="10">
<h:inputText
value="#{categoryBean.currentCategory.name[locale.language]}" />
</h:panelGrid>
</p:tab>
</c:forEach>
</p:tabView>
</h:panelGrid>
<p:commandButton id="saveCategoryButton" value="Save"
oncomplete="categoryDialog.hide()"
actionListener="#{categoryBean.save}"
update="categoryTable, categoryDialog" />
</p:panel>
</p:dialog>
</h:form>
推荐答案
我犯了一个大错误.我用了标签.我应该使用素数.
I made a big mistake. I used tag. I should use for primefaces.
<h:form id="categoryForm">
<p:commandButton id="addCategoryButton" value="New"
onclick="categoryDialog.show();" type="button" />
<p:dataTable var="cat" value="#{categoryBean.categoryList}"
rowKey="#{cat.id}" paginator="true" rows="10"
selection="#{categoryBean.selectedCategories}" id="categoryTable"
widgetVar="categoryTable">
<f:facet name="header">
Category List
</f:facet>
<p:column selectionMode="multiple" />
<p:column headerText="Name" sortBy="#{cat.name}"
filterBy="#{cat.name}" id="name">
#{cat.name[categoryBean.currentLocale.language]}
</p:column>
<p:column headerText="Sort Order" sortBy="#{cat.sortOrder}"
filterBy="#{cat.sortOrder}" id="sortOrder">
#{cat.sortOrder}
</p:column>
<p:column headerText="Actions" id="actions">
<p:panelGrid columns="2" styleClass="actions" cellpadding="2">
<p:commandButton action="#{categoryBean.edit(cat)}" value="Edit" />
<p:commandButton value="Delete"
onclick="deleteConfirmation.show()">
<f:setPropertyActionListener value="#{cat}"
target="#{categoryBean.currentCategory}" />
</p:commandButton>
</p:panelGrid>
</p:column>
</p:dataTable>
<p:confirmDialog id="deleteConfirmDialog" message="Are you sure?"
header="Initiating destroy process" severity="alert"
widgetVar="deleteConfirmation">
<p:commandButton id="confirm" value="Yes Sure"
update=":categoryForm:categoryTable"
oncomplete="deleteConfirmation.hide()"
actionListener="#{categoryBean.delete}" />
<p:commandButton id="decline" value="Not Yet"
onclick="deleteConfirmation.hide()" type="button" />
</p:confirmDialog>
<p:dialog id="categoryDialog" header="Category Detail"
widgetVar="categoryDialog" resizable="false" style="width:90%;"
showEffect="explode" hideEffect="explode">
<p:panel id="panel" header="Edit Category"
style="margin-bottom:10px;">
<p:messages id="messages" />
<h:panelGrid columns="3">
<h:outputLabel for="nameTabView" value="Name: " />
<p:tabView id="nameTabView">
<c:forEach var="locale" items="#{categoryBean.userLocales}">
<p:tab title="#{locale.displayLanguage}">
<h:panelGrid columns="2" cellpadding="10">
<h:inputText
value="#{categoryBean.currentCategory.name[locale.language]}" />
</h:panelGrid>
</p:tab>
</c:forEach>
</p:tabView>
</h:panelGrid>
<p:commandButton id="saveCategoryButton" value="Save"
oncomplete="categoryDialog.hide()"
actionListener="#{categoryBean.save}"
update="categoryTable, categoryDialog" />
</p:panel>
</p:dialog>
</h:form>
谢谢您的帮助
这篇关于Primefaces:confirmDialog中的commandButton无法以相同形式更新数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!