Primefaces 3.5, Omnifaces 1.6
I have a group of buttons with icons. The buttons have an action to do on the page (such as delete or add new row in datatable). I want to add new "something" that looks exactly as buttons do, but with an external link. If I click on this new button, new tab/window have to be opened. For that purpose I am using p:commandButton
and h:outputLink
.
<p:commandButton action="#{bean.do1}" icon= ...>
<p:commandButton action="#{bean.do2}" icon= ...>
<h:outputLink value="#{bean.url}" target="_blank">
<i class="icon-external-link"></i>
</h:outputLink>
How can I achieve this ?
The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute. If necessary, set CSS display: inline; on the form to keep it in the flow with the surrounding text. Instead of <input type="submit"> in above example, you can also use <button type="submit"> .
Use a p:button
, which acts like a link:
<p:button href="http://www.stackoverflow.com" value="Go to SO" />
If you want a blank target and starting from Primefaces 3.5.5, there's the chance to use the
target
attribute directly:
<p:button target="_blank" href="http://www.stackoverflow.com" value="Go to SO" />
When being below PF 3.5.5, you could do some javascript to open it in a blank target:
<p:button value="Go to SO" onclick="window.open('http://www.stackoverflow.com')" />
All of the choices above use javascript to change the browser's
window location. In order to generate a bot-harvestable HTML
link element, make use of a h:outputLink
(or just a plain HTML a
element),
and style it using Primefaces' classes:
<h:outputLink value="http://www.stackoverflow.com"
styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
<span class="ui-button-text">Go to SO</span>
</h:outputLink>
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With