Home > jee-light > How to open a new window from JSF commandLink tag?

How to open a new window from JSF commandLink tag?

Some of the JSF reference implementations (including jsf-html) do not provide commandLink option with a target attribute, which we could use as in <a href=”myurl” target=”_blank”/>. This quick tip would explore 2 ways to do that

1) If there in only single commandLink in the form, you could specify it the enclosing form level as given below:

<h:form id="form1" target="blank">
...
<h:commandLink action="#{mybean.myaction}" id="link" value="Click here to open new window">
</h:commandLink>
...
</h:form>

2) If there are multiple commandLink tags in the enclosing form, you could use onclick attribute to navigate in a new page:

<h:form id="form2">
...
<h:commandLink action="#{mybean.myaction1}" id="link1" value="Click here to open new window1" onclick="javascript:window.open('#{request.contextPath}/myview.1jsf');">
</h:commandLink>
....
<h:commandLink action="#{mybean.myaction2}" id="link2" value="Click here to open new window2" onclick="javascript:window.open('#{request.contextPath}/myview2.jsf');">
</h:commandLink>
...
</h:form>
Categories: jee-light Tags: ,
  1. December 3rd, 2009 at 01:23 | #1

    target=”_blank” works for h:commandLink. For example I use the below code.

  2. December 3rd, 2009 at 01:24 | #2

    <h:commandLink action=”#{tutlist.showViewPage}” target=”_blank”>
    <h:graphicImage value=”/img/ok.png” style=”border:none;”/>
    </h:commandLink>

  1. No trackbacks yet.