如何使用PrimeFaces按钮在新窗口中打开任意URL

Ale*_*bos 6 jsf primefaces

我有以下输出链接,它的工作:

<h:outputLink value="#{verDocumentoController.url()}" target="_blank">
    show document
</h:outputLink>
Run Code Online (Sandbox Code Playgroud)

它打开一个在新窗口中作为bean属性获取的URL.

但是,我想将链接转换为PrimeFaces中的按钮.我试过如下:

<p:commandButton value="show document" action="#{verDocumentoController.url()}" 
    onclick="form.target='_blank'" ajax="false" />
Run Code Online (Sandbox Code Playgroud)

但它只在新窗口中重新打开当前页面,而不是指定为bean属性的URL.我怎么能实现这个目标呢?

Bal*_*usC 10

<p:commandButton>由其父指定的基本提交POST请求的URL <h:form>,默认确实给当前请求的URL(你知道,"回传").该action属性基本上调用bean方法,并使用返回的值作为导航案例结果.URL不一定代表合理的导航案例结果.

只需使用window.open()简单的<p:button>.

<p:button value="show document" 
    onclick="window.open('#{verDocumentoController.url()}');return false;" />
Run Code Online (Sandbox Code Playgroud)

您也可以在a上执行此操作<p:commandButton>,但这不必要地过于复杂.