• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

CommandLink Vs OutputLink in JSF

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

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

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>
<h:outputText 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
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
reply
    Bookmark Topic Watch Topic
  • New Topic