我遇到了JavaEE和Primefaces的问题。
我有一个数据表,其中包含用于删除条目的按钮。按钮就像一个魅力。
在删除条目之前我想要一个确认对话框,但我在这里遇到了问题。确认对话框在代码中但不显示。单击按钮后立即执行操作。
当我点击之前没有任何特殊功能的按钮(在示例中为编辑按钮)时,删除按钮的确认对话框可以正常工作。
这是.xhtml文件:
<ui:define name="content">
<h1>ProbeType overview</h1>
<p>Use this site to view available probetypes and if necessary to
edit them.</p>
<h:form id="probelist">
<p:column style="width: 40px">
<p:commandButton icon="ui-icon-pencil" id="btnEdit"
action="#{editProbeBean.editProbeType(probetype)}" update="@all" />
</p:column>
<p:column style="width: 40px">
<p:commandButton icon="ui-icon-cancel" id="btnDel"
action="#{probeBean.deleteProbeType(probetype)}" update="@all">
<p:confirm header="Confirm"
message="Would you like to delete this probetype with all corresponding data?"
icon="ui-icon-alert"></p:confirm>
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Yes" type="button" id="btnYes"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
</ui:define>
这是Bean文件:
public class ProbeBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<ProbeType> probetypes;
@Inject
private ProbeTypeFacadeLocal probeTypeFacade;
public List<ProbeType> getProbeTypes() {
probetypes = probeTypeFacade.getAllProbeTypes();
return probetypes;
}
public String deleteProbeType(ProbeType probe) {
try {
probeTypeFacade.deleteProbeType(probe);
probetypes = probeTypeFacade.getAllProbeTypes();
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("errors", new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Error!", "Error while deleting, are there still Jobs in database?"));
}
return "probelist.xhtml";
}
解决方案可能很简单,但如果有人帮我解决问题,我将不胜感激。