aspose file tools*
The moose likes JSF and the fly likes CommandLink Vs OutputLink in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "CommandLink Vs OutputLink in JSF" Watch "CommandLink Vs OutputLink in JSF" New topic
Author

CommandLink Vs OutputLink in JSF

Srinivasa Nandula
Greenhorn

Joined: Jan 29, 2009
Posts: 1
Hi,

In the below example, I need "someString" to form my URL and once the URL is formed it should take me to the new page.

When I am using outputLink component, hiddenVar parameter is going as null in to the backing bean. But it is taking me to the new page.

<hutputLink value="#{myBean.getURL}">
<f:param name="hiddenVar" value="someString"></f:param>
<hutputText styleClass="graybold" value="Click Here"/>
</hutputLink>

When I am using commandLink component, hiddenVar parameter is going as "someString" in my backing bean and the URL is being formed, but it is not taking me to the new page.

<h:commandLink action="#{myBean.getURL}">
<f:param name="hiddenVar" value="someString"></f:param>
<hutputText styleClass="graybold" value="Click Here"/>
</h:commandLink>

If anyone has any idea on this, please share your thoughts. I appreciate your help in this regard.

Thanks,
Karsid
Sergey Smirnov
Ranch Hand

Joined: May 29, 2003
Posts: 167
The difference is much bigger than you expects.

outputLink is an equivalent of the < a href >. From the JSF point of view, it is alway a non-faces request. According to the JSF Specification, it is called "non-faces request generates faces response". The JSF lifecycle create the new view (based on the page you use in URL) and jumps directly to the sixth phase - Render Response. The value from the f:param is not assigned because JSF bypass all the phases such assignment might be performed.

commandLink is one of way for JSF postback. I.e. it triggers the form post that is associated with "faces request" on the server and JSF walks thru the JSF lifecycle. In same cases ( like session cannot be restored, validation failed, conversion failed, update more failed) particular phases might be bypassed. The application might jump to the next page only if the whole JSF lifecycle is passed and the navigation to the next page in performed at the end of the fifth phase.

According to your code snippet, you are completely misunderstand what the h:commandLink is about. The action attribute is NOT an URL to the next page. The action attribute should return a literal value that is used in the navigation case declared in the faces-config.xml file.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: CommandLink Vs OutputLink in JSF