Pradeep Gamage
Pradeep Gamage

Reputation: 615

How to open new window with backing bean?

I am using JSF for my project front end. How I can I open a new window with backing bean?

Upvotes: 4

Views: 10814

Answers (2)

Erik Kaju
Erik Kaju

Reputation: 3173

In addition to BalusC answer. Kind of hacky solution in situation when:

  • commandLink cannot be used in UI (because of page styling or any other reason)
  • target of the form cannot be changed

    <!-- Group and render them together.-->
    <h:panelGroup rendered="#{mybean.showButton}">
    
    <!-- Visible and clickable commandButton. No action, just onclick js event.-->
    <h:commandButton value="My Commandbutton"
    onclick="document.getElementById('myForm.realTargetBlankLink').click();"/>
    
    <!-- Invisible link. Action, target _blank.-->
    <h:commandLink id="realTargetBlankLink" action="#{myBean.myDesiredAction}"
    target="_blank"/>
    
    </h:panelGroup>
    

Upvotes: 0

BalusC
BalusC

Reputation: 1108642

Set target="_blank" on the <h:commandLink> or <h:form>.

E.g.

<h:form>
    <h:commandLink value="Open in new window" action="#{bean.action}" target="_blank" />
</h:form>

or

<h:form target="_blank">
    <h:commandButton value="Open in new window" action="#{bean.action}" />
</h:form>

Upvotes: 6

Related Questions