Validation p:对话框在ajax=";提交的验证错误时关闭;假“;,如何保持对话框打开?
我有以下Validation p:对话框在ajax=";提交的验证错误时关闭;假“;,如何保持对话框打开?,validation,jsf,primefaces,dialog,download,Validation,Jsf,Primefaces,Dialog,Download,我有以下 内部下载对话框.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
内部下载对话框.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上,对话框保持关闭状态。但当我点击父页面上的下载按钮时,对话框窗口再次出现,并在内部对话框窗口中包含错误消息
谢谢您的帮助。如果您将downloadFile方法的一部分委托给另一个方法怎么办 在这种情况下,您需要另一种方法(我们称之为prepareDownloadFile),它将使用ajax调用。完成此方法后,您可以检查错误。如果一切顺利,您可以调用remoteCommand(ajax=false)将文件发送给用户 另一个想法是使用iframe。看看这个 希望有帮助
<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: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>
<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>