Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling one JSF external link to make it look like a button

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 ?

like image 439
Tony Avatar asked Sep 20 '13 12:09

Tony


People also ask

How do I turn a link into a button in HTML?

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"> .


1 Answers

  • 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:

  • window.location.href vs clicking on an Anchor
like image 132
Xtreme Biker Avatar answered Sep 19 '22 18:09

Xtreme Biker