如果验证未失败,如何使用target ="_ blank"在新窗口中打开报表

sho*_*uts 5 validation jsf report new-window primefaces

我有一个报告需要在另一个选项卡中打开,但只有在验证没有失败时才会打开.就我而言,验证失败,同一页面在另一个带有验证错误的选项卡中打开.

Bal*_*usC 5

Luiggi 已经回答了 POST 问题。但是,如果报告可通过 GET 请求获得,则还有其他方法。

  1. 使用window.open()oncomplete

     <h:form>
         ...
         <p:commandButton action="#{bean.submit}" update="@form" 
             oncomplete="if (args &amp;&amp; !args.validationFailed) window.open('reportURL')" />
     </h:form>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 或者有条件地渲染一个<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)
  3. 或者将 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}')