First, in ancient JSF versions there was a bug which caused that commandlinks can't work that way. Ensure that you're using the latest version/build. Mojarra is available here and MyFaces is available here.
As to your actual problem, a commandlink basically generates a link which submits the parent form. It's supposed to be placed inside a h:form
, but here you just want a plain vanilla link. In this case, replace it by h:outputLink
. Don't forget to add return false;
to end of click event to block the link's default action.
<h:outputLink
value="#{managePersonalization.disclaimerURL}"
onclick="openDisclaimer(this); return false;">
<h:outputText value="Disclaimer" />
</h:outputLink>
Further, the value
attribute actually ends up as href
attribute of the generated <a>
element, so your JavaScript needs to be fixed that it gets the URL from href
attribute rather than the value
attribute (JavaScript doesn't see the JSF source code, but only its generated HTML output!):
function openDisclaimer(link) {
window.open(link.href);
}
You also see that document.getElementById
is removed because it makes no sense as you already have the sole element as function argument! ;)
You can even get rid of the whole function:
<h:outputLink
value="#{managePersonalization.disclaimerURL}"
onclick="window.open(this.href); return false;">
<h:outputText value="Disclaimer" />
</h:outputLink>
Alternatively, if you actually want a worthfully tab/window instead of a popup window, then you can also just make use of the target
attribute which you set to _blank
:
<h:outputLink
value="#{managePersonalization.disclaimerURL}"
target="_blank">
<h:outputText value="Disclaimer" />
</h:outputLink>