2015-06-03 49 views
6

我有它的工作的下方輸出鏈接打開新窗口任意網址:如何使用PrimeFaces按鈕

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

它打開在一個新窗口Bean屬性得到一個URL。

但是,我想將鏈接變成PrimeFaces look'n'feel中的按鈕。我試過如下:

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

但它只是重新打開一個新窗口中的當前頁面,而不是指定爲bean屬性的URL。無論如何我怎麼能做到這一點?

回答

10

<p:commandButton>基本上向其父母<h:form>指定的URL提交POST請求,該請求默認實際上是當前請求URL(您知道,「回發」)。 action屬性基本上調用一個bean方法,並使用返回的值作爲導航案例結果。 URL不一定代表明智的導航案例結果。

只需使用window.open()而不是簡單的<p:button>

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

你也可以做到這一點上<p:commandButton>,但這是不必要的過於複雜。