Saturday, September 28, 2013

Creating hyperlink with JSF components

normally JSF components accept an outcome from navigation case to generate hyperlink.
eg,
<h:link value="my link" outcome="MY_OUTCOME" />

<h:commandButton value="my button" action="MY_OUTCOME" />

<h:outputLink value="MY_OUTCOME">my link</h:outputLink />

But hyperlink generated with JSF outcome is only within the same application.
That's mean hyperlink generated with JSF components are unable to navigate to other sites. eg, google.com.

This problem could be resolved by <h:outputLink /> where the value attribute also accepts an URL.
eg.
<h:outputLink value="www.google.com">
    <h:outputText value="Google" />
    <f:param name="param1" value="value1" />
    <f:param name="param2" value="value2" />
</h:outputLink>

With the above codes, the <h:outputLink /> component able to generate hyperlink to www.google.com.

<f:param /> is optional, required only when passing parameters
eg.
www.google.com?param1=value1&param2=value2


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...