我有以下<p:dialog>
p:对话框在ajax =“false”的提交验证错误时关闭,如何保持对话框打开?
<p:dialog id="dlgDownload" header="#{appmsg['header.download.popup']}" widgetVar="downloadDlg" resizable="true" modal="true" closable="true" width="640" dynamic="false">
<h:form id="frmDownload">
<ui:include src="downloadDialog.xhtml" />
</h:form>
</p:dialog>
包含文件包含以下下载按钮:
<p:commandButton id="btnDlgDownload" value="#{appmsg['action.download.label']}" title="#{appmsg['action.download.label']}"
icon="ui-icon-arrowthickstop-1-s" ajax="false" oncomplete="if (!args.validationFailed){downloadDlg.hide();} else {downloadDlg.show();}" process="@this" update=":#{p:component('pnlDownload')}" >
<p:fileDownload value="#{downloadController.downloadFile()}" />
</p:commandButton>
这里使用<p:fileDownload>
下载该文件,这意味着我必须使用ajax="false"
为<p:fileDownload>
触发。
但是,如果在对话框中存在验证失败,则会看到对话框窗口关闭。我希望在对话窗口中显示错误消息,而不是在主页面中显示。
如何保持对话框打开,以便我可以在对话框窗口中显示错误消息?
@Balusc请找我的SSCCE 尝试基本上是有parent.xhtml在下载按钮所在,并有嵌入在p一个downloadDialog.xhtml:对话框
<p:messages id="globalMessages" globalOnly="true" showDetail="true"
showSummary="true" closable="true" />
<h:form = "parentForm" >
<p:commandButton id="btnDownload"
value="Download"
title="Download"
icon="ui-icon-arrowthickstop-1-s" onclick="downloadDlg.show();">
</p:commandButton>
</h:form>
<p:dialog id="dlgDownload" header="Download" widgetVar="downloadDlg" resizable="true"
modal="true" closable="true" width="640" dynamic="false" visible="#{frmDownload.submitted and facesContext.validationFailed}">
<h:form id="frmDownload" binding="#{frmDownload}">
<ui:include src="downloadDialog.xhtml" />
</h:form>
</p:dialog>
内downloadDialog .xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<p:outputPanel id="pnlDownload">
<h:panelGrid id="dateDisplayGrid" columns="4" style="margin-bottom:10px" cellpadding="5" rendered="#{downloadForm.displayDates}">
<p:calendar id="strtdt" readonlyInput="true" size="12" value="#{downloadForm.startDate}" >
</p:calendar>
<h:outputText value="#{appmsg['label.to']}" />
<p:calendar id="enddt" readonlyInput="true" size="12" value="#{downloadForm.endDate}"
pattern="#{dateFormatting.shortDateFormat}" navigator="true" >
<f:validator validatorId="dateRangeValidator" />
<f:attribute name="startDate" value=":#{p:component('strtdt')}" />
</p:calendar>
<p:message id="dateError" for="enddt" showDetail="true" showSummary="false"></p:message>
</h:panelGrid>
<p:commandButton id="btnDlgDownload" value="Download" title="Download"
icon="ui-icon-arrowthickstop-1-s" ajax="false" oncomplete="if(!args.validationFailed)downloadDlg.hide();" >
<p:fileDownload value="#{downloadController.downloadFile()}" />
</p:commandButton>
<p:button id="btnDlgCancel" value="#{webmsg['action.cancel']}" onclick="downloadDlg.hide(); return false" href="#" />
</p:panel>
</p:outputPanel>
</ui:composition>
当我点击对话窗口的下载按钮时,错误显示在父html上,对话框仍然关闭。但是,当我点击父页面上的下载按钮时,对话框窗口重新出现,并在内部对话窗口中包含错误消息。
感谢您的任何帮助。