4

How can I set _blank as target of a h:button or p:button?

Right now I have a simple link:

<h:outputLink value="#{bean.url}" target="_blank">
 <h:outputText value="Link" />
</h:outputLink>

But I wanted it to look like a button (a primefaces styled button if possible) so I decided to change it by a p:button.

<p:button value="Link" href="#{bean.url}" />

But now I can't set the target value as I want.

Does anybody has an idea?

userk
  • 169
  • 2
  • 3
  • 9

3 Answers3

11

A little javascript will help:

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

The EL expression will be replaced before javascript is executed.

WhyNotHugo
  • 9,423
  • 6
  • 62
  • 70
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
0

I used :

<h:form target="_blank">
      <p:commandButton value="Run" action="#{bean.createReport}"  />
    </h:form>

and this is ok.

Alex Ricardo
  • 41
  • 1
  • 2
-2

add ajax="false" to primefaces commandButton set target in p:button, not in form

jdbenitez
  • 15
  • 1
  • 5