siva636
siva636

Reputation: 16441

What is the JSF2.0 equivalent of the HTML anchor tag

When I use the h:link tag as follows, the JSF system reports as This link is disabled because a navigation case could not be matched.

<h:link rendered="#{empty applicationScope.rendered ? false : true}" disabled="#{applicationScope.disabled eq 'true' ? true : false}" outcome="http://www.myblogname.blogspot.com/" >
 <h:graphicImage url="#{applicationScope.url}"    alt="#{applicationScope.alt}" title="#{applicationScope.title}" styleClass="rGap ui-corner-all" />  
</h:link>

It seems it is searching for an internal navigation case, but how can I specify an external hyperlink?

Summery of the question: What is the JSF equivalent of the following HTML?

<a href="http://www.amazon.com" > Amazon </a>

Upvotes: 2

Views: 7122

Answers (1)

Zack The Human
Zack The Human

Reputation: 8481

Try using the h:outputLink tag. Use value attribute to specify the rendered href.

<h:outputLink id="amazonLink" value="http://www.amazon.com">
  Amazon
</h:outputLink>

It should be possible to adapt your sample code like this:

<h:outputLink 
  rendered="#{empty applicationScope.rendered ? false : true}" 
  disabled="#{applicationScope.disabled eq 'true' ? true : false}" 
  value="http://www.myblogname.blogspot.com/">
    <h:graphicImage 
      url="#{applicationScope.url}" 
      alt="#{applicationScope.alt}" 
      title="#{applicationScope.title}" 
      styleClass="rGap ui-corner-all" />  
</h:outputLink>

Note: I don't think the h:outputLink tag has a disabled attribute, so setting it to true or false (like in your code sample above) may not have an effect. You'll have to try it and see.

As @Matteo brought out in a comment, the disabled attribute should work with the h:outputLink tag.

Upvotes: 4

Related Questions