Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Daniel Reznick
Ranch Hand
Posts: 50
Eclipse IDE Google App Engine jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...


Regards

Daniel Reznick...
 
Hany Shafik
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Ranch Hand
Posts: 82
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Ed
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Dan Allen
Author
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 https://javaserverfaces-spec-public.dev.java.net/issues/), 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.
 
Lincoln Baxter
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic