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

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

问题描述

我需要通过POST点击< h:commandButton> 在新窗口中打开一个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 =父母< h:form> 中的_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天全站免登陆