如何使用PrimeFaces按钮在新窗口中打开任意URL [英] How to open an arbitrary URL in new window using a PrimeFaces button
问题描述
我有下面的输出链接可以完成其工作:
I have the below output link which does its job:
<h:outputLink value="#{verDocumentoController.url()}" target="_blank">
show document
</h:outputLink>
它将在新窗口中打开作为bean属性获得的URL.
It opens an URL obtained as a bean property in a new window.
但是,我想将链接变成PrimeFaces外观上的一个按钮.我尝试如下:
However, I'd like to turn the link into a button in PrimeFaces look'n'feel. I tried as below:
<p:commandButton value="show document" action="#{verDocumentoController.url()}"
onclick="form.target='_blank'" ajax="false" />
但是它只会在新窗口中重新打开当前页面,而不是指定为bean属性的URL.反正我该如何实现?
But it only reopens the current page in a new window and not the URL specified as bean property. How can I achieve this anyway?
推荐答案
<p:commandButton>
基本上向其父<h:form>
指定的URL提交POST请求,该URL实际上默认为当前请求的URL(您知道, 回发"). action
属性基本上会调用bean方法,并将返回的值用作导航案例的结果. URL不一定代表明智的导航案例结果.
The <p:commandButton>
basically submits a POST request to the URL as specified by its parent <h:form>
, which defaults indeed to the current request URL (you know, "postback"). The action
attribute basically invokes a bean method and uses the returned value as navigation case outcome. An URL does not necessarily represent a sensible navigation case outcome.
只需在简单的<p:button>
上使用window.open()
.
<p:button value="show document"
onclick="window.open('#{verDocumentoController.url()}');return false;" />
您也可以在<p:commandButton>
上执行此操作,但这不必要太复杂.
You can also do this on a <p:commandButton>
, but that's unnecessarily overcomplicated.
这篇关于如何使用PrimeFaces按钮在新窗口中打开任意URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!