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

2

7

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?

Cuthburt answered 11/11, 2015 at 17:16 Comment(1)
3 ideas: try with ajax="false". Try with return "/application-container.xhtml?faces-redirect=true". And try giving it a hardcoded url instead of action, if this works target and action apparently dont work togetherDoreathadoreen
A
8

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!

Aluin answered 11/11, 2015 at 19:54 Comment(0)
J
1

You can add the attribute ajax="false" along with target="_blank" to the p:menuitem. It should look like this:

<p:menuitem
    value="#{caseList['caseManagement.case.newtab']}" 
    target="_blank"
    ajax="false"
    action="#{applicationManagementBean.openNewTabDetail(unassignedCase)}">
Judsonjudus answered 16/5, 2023 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.