2

Simple question (using JSF 2.0 and primefaces 2.2.1):

I need to create a button or link that will take me to an external url (i.e. www.facebook.com) and I need that button to look like the facebook icon instead of having the literal word. How can I do this? Thank you.

1 Answer 1

6

You basically want to end up with the following in the JSF-generated HTML code:

<a><img /></a>

There are several ways how to achieve this in JSF.

  1. Just do it:

    <a href="http://www.facebook.com">
      <img src="#{request.contextPath}/resources/images/facebook.png" />
    </a>
    
  2. Use <h:graphicImage>:

    <a href="http://www.facebook.com">
      <h:graphicImage name="images/facebook.png" />
    </a>
    
  3. Eventually, with <h:outputLink>:

    <h:outputLink value="http://www.facebook.com">
      <h:graphicImage name="images/facebook.png" />
    </h:outputLink>
    

What way to choose depends on whether you really need it to be a JSF component. E.g. in order to be able to grab/manupulate it in backing bean, and/or to re-render by ajax, etc.

Sign up to request clarification or add additional context in comments.

2 Comments

Small correction. It is <h:graphicImage value=""/>, not <h:graphicImage name=""/>.
@Srinivas: only if you're using legacy JSF 1.x or don't make use of JSF 2.x resource management for some unclear reason. See also stackoverflow.com/questions/8367421/… Since JSF2, it's strongly recommend to make use of JSF resource management as it gives more benefits (caching, versioning, localization, combining, etc). The answer is in this case really correct and you're just doing it wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.