File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF 2 : what is all the buzz about the <h:link> and <h:button> ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF 2 : what is all the buzz about the <h:link> and <h:button> ???" Watch "JSF 2 : what is all the buzz about the <h:link> and <h:button> ???" New topic

JSF 2 : what is all the buzz about the <h:link> and <h:button> ???

Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

Hi I'm new to jsf 2 (worked couple of years with jsf 1.2)

and I'm trying to figure out what so special about the <h:link> and <h:button> and what it is good for?

and regarding to bookmarkabilty that can be achieved with this two new tags... isnt the same thin can be achieved with "redirect" tag added to config xml of the jsf ?

thanks ahead...


Daniel Reznick...
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
I guess they aren't the same, In JSF 2.0 they are used as direct links they don't issue a post request and then a redirect, instead they issue a get request directly to the URL specified, so they don't have an action attribute. Besides they have more feature that didn't exist before e.g. Integrating with View Parameters.

You can find more information in whats-new-in-jsf-2
Ed Burns
Ranch Hand

Joined: Sep 11, 2006
Posts: 82
I also recommend Andy Schwartz's blog entry. Also, these two tags work very well with the new f:viewParam tag. I have substantial content in this starting on page 127 of the book.

Gian Franco
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
This is the entry Andy Schwartz

So if I understand correctly the new tag <h:link> is a simplification of what in Struts 1
would have been done more or less like:

Where you had to specify the whole url...

"Eppur si muove!"
Dan Allen
Ranch Hand

Joined: Mar 05, 2003
Posts: 164
These new components are exciting mainly because they were sorely missed in earlier versions of JSF. At last, they are available. The reason they were missed is because regular hyperlinks happen to be the most common way to link pages (the other way being a form submission). So the thing that you had to do the most often was kind of difficult. Your only option was to use <h: outputLink>. But that component has no concept of view IDs, so the target would have to be a URL that included the servlet mapping (*.faces or /faces/*).

The <h:link> and <h:button> are also compelling because they can manage the query string for you when combined with view parameters. If you've ever created a search form like bugzilla (see, you would have had to itemize and propagate each individual request parameter that makes up the search anywhere you have links on the page. View parameters allow you to declare the request parameters on the target page (as view parameters) and those parameters will automatically be added to any links that target that view ID. So it turns out to be very convenient.

Dan Allen | | Author of Seam in Action -
Lincoln Baxter

Joined: Aug 25, 2008
Posts: 24
Well said, Dan!

Another benefit of the <h:link> and <h:button> tags is that they enforce the POST, Redirect, GET pattern, which provides a much more consistent, user-friendly experience that is safer from potential issues with duplicate form submissions the "back" button.

Lincoln Baxter, III | [url][/url] | Creator of: PrettyFaces - Bookmarks, Navigation, and Dynamic Parameters for JSF
I agree. Here's the link:
subject: JSF 2 : what is all the buzz about the <h:link> and <h:button> ???
jQuery in Action, 3rd edition