File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

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


Regards

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
author
Ranch Hand

Joined: Sep 11, 2006
Posts: 82
    
    5
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

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


Dan Allen | http://mojavelinux.com | Author of Seam in Action - http://mojavelinux.com/seaminaction
Lincoln Baxter
Greenhorn

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]http://ocpsoft.com/[/url] | Creator of: PrettyFaces - Bookmarks, Navigation, and Dynamic Parameters for JSF
 
Consider Paul's rocket mass heater.
 
subject: JSF 2 : what is all the buzz about the <h:link> and <h:button> ???
 
Similar Threads
JSF URL annoyance in JSF 2?
how to create type button in JSF using SUN RI
User who is logged in simultaneously from different browser ... how to forcely logout the first user
Matrix display in JSF
Is it possible to make controls on h:dataTable work after a back button has been used.