Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jsf - How to use target=“_blank” to open report in new window only if validation has not failed

I have a report that needs to be opened in another tab, but only if the validation hasn't failed. In my case, the validation fails and the same page opens in another tab with the validations errors.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Luiggi has answered the POST matter. If the report is however available by a GET request, then there are other ways.

  1. Use window.open() in oncomplete.

     <h:form>
         ...
         <p:commandButton action="#{bean.submit}" update="@form" 
             oncomplete="if (args &amp;&amp; !args.validationFailed) window.open('reportURL')" />
     </h:form>
    
  2. Or conditionally render a <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>
    
  3. Or use PrimeFaces Primefaces#execute() with window.open().

     public void submit() { 
         // ...
         PrimeFaces.current().executeScript("window.open('reportURL');");
     }
    

The first way requires the URL to be already definied before submit, the latter two ways allows you to use a dynamic URL like so window.open('#{bean.reportURL}').


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...