sho*_*uts 5 validation jsf report new-window primefaces
我有一个报告需要在另一个选项卡中打开,但只有在验证没有失败时才会打开.就我而言,验证失败,同一页面在另一个带有验证错误的选项卡中打开.
Luiggi 已经回答了 POST 问题。但是,如果报告可通过 GET 请求获得,则还有其他方法。
使用window.open()在oncomplete。
<h:form>
...
<p:commandButton action="#{bean.submit}" update="@form"
oncomplete="if (args && !args.validationFailed) window.open('reportURL')" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
或者有条件地渲染一个<h:outputScript>with window.open()。
<h:form>
...
<p:commandButton action="#{bean.submit}" update="@form" />
<h:outputScript rendered="#{facesContext.postback and not facesContext.validationFailed}">
window.open('reportURL');
</h:outputScript>
</h:form>
Run Code Online (Sandbox Code Playgroud)
或者将 PrimeFacesPrimefaces#execute()与window.open().
public void submit() {
// ...
PrimeFaces.current().executeScript("window.open('reportURL');");
}
Run Code Online (Sandbox Code Playgroud)
第一种方式要求在提交之前已经定义好 URL,后两种方式允许您使用像这样的动态 URL window.open('#{bean.reportURL}')。