jsfjsf-2primefacesmenuitemnew-window

target="_blank" in p:menuitem doesn't open new tab


I am using primefaces 5.1, liferay 6.2.0-ga2 and JSF2. I have a page with button. When I press right-click a context menu with one menuitem is displayed. That menuitem must open a new tab, but it doesn't.

<p:commandButton id="viewUnassignedCase"
    action="application-container" styleClass="icon fa fa-eye">
    <f:setPropertyActionListener
        target="#{applicationManagementBean.application}"
        value="#{unassignedCase}" />

    <f:setPropertyActionListener
        target="#{applicationManagementBean.activeIndexTab}" value="0" />
</p:commandButton>

<p:contextMenu for="viewUnassignedCase" id="tableMenu" 
    widgetVar="tableMenu">
    <p:menuitem value="#{caseList['caseManagement.case.newtab']}" 
        target="_blank"
        action="#{applicationManagementBean.openNewTabDetail(unassignedCase)}">
    </p:menuitem>
</p:contextMenu>

and the bean

public String openNewTabDetail(final FlexibleDomain application)
{
setApplication(application);
return "application-container";
}

How can I fix it?


Solution

  • There's an issue tagged as "Won'tFix" on Primefaces's GoogleCode for this behavior (p:menuItem not opening a new window using action).

    In your case you would need to adapt your action-based navigation for a url based one.

    I can't really figure out how to make it work in your project, but my best bet is trying something like this:

    <p:contextMenu for="viewUnassignedCase" id="tableMenu" 
                                widgetVar="tableMenu">
                                <p:menuitem value="#{caseList['caseManagement.case.newtab']}" 
                                    target="_blank"
                                    url="www.yoururl.com/yourdesiredpath">
                                </p:menuitem>
                            </p:contextMenu>
    

    In the worst case scenario you should try to override Primefaces's p:menuitem default behavior or maybe try to use another component that support this kind of implementation.

    Good luck!