使用 h:commandButton 通过 POST 打开新窗口 [英] Open new window by POST using h:commandButton

查看:29
本文介绍了使用 h:commandButton 通过 POST 打开新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过单击 的 POST 在新窗口中打开一个 JSF 页面.我知道我可以使用 JavaScript 来实现这一点.但我想使用 JSF 而不是 JavaScript 来实现这一点.

I need to open a JSF page in a new window by POST on click of a <h:commandButton>. I know I can acheive this using the JavaScript. But I would like to achive this using JSF and not JavaScript.

我怎样才能做到这一点?我使用的是 JSF 2.0.

How can I achieve this? I'm using JSF 2.0.

推荐答案

唯一的非 JS 方式是在父 中设置 target="_blank".

The only non-JS way is to set target="_blank" in the parent <h:form>.

<h:form target="_blank">
    ...
    <h:commandButton value="Open in new Window" />
</h:form>

然而,这会影响以相同形式执行的所有非 ajax(!) 操作.因此,如果您很聪明,请将不应在新窗口中打开的操作设为 ajax 操作.但是,ajax 也是 JavaScript,您提到您不想使用 JS(希望您在发现 PrimeFaces 中实际上充满了 JavaScript 时不要感到震惊).

This however affects all non-ajax(!) actions which are performed in the very same form. So if you're smart, make the action which shouldn't open in a new window an ajax action. However, ajax is also JavaScript and you mentioned that you don't want to use JS (I hope you don't get shocked once you discover that PrimeFaces is actually full of JavaScript).

如果您绝对需要将其限制为单个操作,那么您真的不能四处求助于 JavaScript.

If you absolutely need to restrict it to a single action, then you really can't go around asking little help to JavaScript.

<h:form>
    ...
    <h:commandButton value="Open in new Window" onclick="this.form.target='_blank'" />
</h:form>

这篇关于使用 h:commandButton 通过 POST 打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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