如何使用 PrimeFaces 按钮在新 window 中打开任意 URL
How to open an arbitrary URL in new window using a PrimeFaces button
我有下面的输出 link 它完成了它的工作:
<h:outputLink value="#{verDocumentoController.url()}" target="_blank">
show document
</h:outputLink>
它在新的 window 中打开一个作为 bean 属性 获得的 URL。
但是,我想将 link 变成 PrimeFaces 外观中的按钮。我试过如下:
<p:commandButton value="show document" action="#{verDocumentoController.url()}"
onclick="form.target='_blank'" ajax="false" />
但它只会在新的 window 中重新打开当前页面,而不是指定为 bean 属性 的 URL。我怎样才能做到这一点?
<p:commandButton>
基本上按照其父 <h:form>
的指定向 URL 提交一个 POST 请求,它确实默认为当前请求 URL (你知道,"postback")。 action
属性基本上调用 bean 方法并将返回值用作导航案例结果。 URL 不一定代表明智的导航案例结果。
只需在简单的 <p:button>
上使用 window.open()
。
<p:button value="show document"
onclick="window.open('#{verDocumentoController.url()}');return false;" />
您也可以在 <p:commandButton>
上执行此操作,但这过于复杂了。
我有下面的输出 link 它完成了它的工作:
<h:outputLink value="#{verDocumentoController.url()}" target="_blank">
show document
</h:outputLink>
它在新的 window 中打开一个作为 bean 属性 获得的 URL。
但是,我想将 link 变成 PrimeFaces 外观中的按钮。我试过如下:
<p:commandButton value="show document" action="#{verDocumentoController.url()}"
onclick="form.target='_blank'" ajax="false" />
但它只会在新的 window 中重新打开当前页面,而不是指定为 bean 属性 的 URL。我怎样才能做到这一点?
<p:commandButton>
基本上按照其父 <h:form>
的指定向 URL 提交一个 POST 请求,它确实默认为当前请求 URL (你知道,"postback")。 action
属性基本上调用 bean 方法并将返回值用作导航案例结果。 URL 不一定代表明智的导航案例结果。
只需在简单的 <p:button>
上使用 window.open()
。
<p:button value="show document"
onclick="window.open('#{verDocumentoController.url()}');return false;" />
您也可以在 <p:commandButton>
上执行此操作,但这过于复杂了。