使用h:commandButton或p:commandButton打开一个新的窗口/选项卡?

3

要求在按钮点击时打开新窗口/标签页。新窗口应重定向到新的URL或新页面。我尝试了以下代码:

<h:commandButton value="Login" onclick="this.form.target='_blank'"/> 

但是这会再次打开当前页面。我该如何设置新页面或URL在新窗口/选项卡中打开?

1个回答

0

试试这个:

XHTML:

<p:commandButton actionListener="#{backing.popupDlg(row.id)}" immediate="true" value="Dialog">
    <p:ajax event="dialogReturn" update="@form" listener="#{backing.refreshPage}" />
</p:commandButton>

备份:

public void popupDlg(Integer id) {
    //USER CODE
    // DO something with ID

    Map<String, Object> options = new HashMap<String, Object>();
    options.put("modal", true);
    options.put("closable", false);
    options.put("draggable", true);
    options.put("resizable", true);
    options.put("contentHeight", 620);

    RequestContext.getCurrentInstance().openDialog("DlgPage", options, null);
}

同时,它还处理主页面的对话框返回更新/删除/插入,当它在对话框中打开DlgPage.xhtml时。


你的意思是我们将通过actionListener="#{backing.popupDlg(row.id)}"调用后端bean的editDesignationDlg(Integer dsgnId)方法。popupDlg(row.id)只是一个笔误,实际应该是editDesignationDlg或者其他方法。 - Harleen
编辑问题,对我来说,我在p:datatable中使用了这个,所以我将行ID传递给后端方法。如果您有所有标准弹出窗口,则不需要任何ID。您可以从中使用基本思路。因为它非常清晰。 - Sarz
我的要求是在按钮提交时打开一个新的标签页/窗口,而不是在同一页上弹出对话框/弹窗。从您分享的内容中,我无法理解这个逻辑。 - Harleen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接