仅在验证未失败的情况下,如何使用target ="_ blank"在新窗口中打开报告 [英] How to use target=“_blank” to open report in new window only if validation has not failed

查看:101
本文介绍了仅在验证未失败的情况下,如何使用target ="_ blank"在新窗口中打开报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报告需要在另一个选项卡中打开,但前提是验证没有失败.就我而言,验证失败,并且同一页面在另一个标签中打开,并显示验证错误.

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.

推荐答案

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

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

  1. oncomplete中使用window.open().

<h:form>
    ...
    <p:commandButton action="#{bean.submit}" update="@form" 
        oncomplete="if (args &amp;&amp; !args.validationFailed) window.open('reportURL')" />
</h:form>

  • 或使用window.open()有条件地渲染<h:outputScript>.

  • 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>
    

  • 或将PrimeFaces RequestContext#execute()window.open()一起使用.

  • Or use PrimeFaces RequestContext#execute() with window.open().

    public void submit() { 
        // ...
        RequestContext.getCurrentInstance().execute("window.open('reportURL');");
    }
    

  • 第一种方法要求在提交之前已经定义了URL,后两种方法使您可以使用像window.open('#{bean.reportURL}')这样的动态URL.

    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}').

    这篇关于仅在验证未失败的情况下,如何使用target ="_ blank"在新窗口中打开报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆