我有以下<p:dialog>
<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"
for<p:fileDownload>
来触发。
但是如果对话框中的验证失败,那么我会看到对话框窗口被关闭。我希望错误消息显示在对话框窗口中,而不是在主页中。
如何保持对话框打开,以便在对话框窗口中显示错误消息?
@Balusc请在SSCCE上找到我的尝试基本上下载按钮所在的parent.xhtml和p:dialog上嵌入了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 上,并且对话框保持关闭状态。但是当我点击父页面上的下载按钮时,对话框窗口会重新出现,并在内部对话框窗口中包含错误消息。
谢谢你的帮助。