p:commandLink无法在新窗口/选项卡中打开页面 [英] p:commandLink fails to open page in new window/tab

查看:142
本文介绍了p:commandLink无法在新窗口/选项卡中打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个链接,以在其他窗口/选项卡中打开新页面,并显示来自支持bean的某些msg,但操作失败,想知道为什么吗?

I'm trying to create a link to open a new page in a different window/tab and display some msg from backing bean but fail to do it, wonder know why?

这是我的xhtml文件:

here is my xhtml file:

<html:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
  xmlns:ui="http://java.sun.com/jsf/facelets">
  <h:body>
    <h:form id="form66">
    <p:commandLink actionListener="#{testing.getMessage}" action="msg.xhtml" target="_blank">get Msg</p:commandLink>
    </h:form>
  </h:body>
</html>

这是我的Msg.xhtml页面

here is my Msg.xhtml page

<HTML xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:ui="http://java.sun.com/jsf/facelets">
  <h:head>
    <title>testing</title>
  </h:head>
  <h:body>
    <div class="div">
      <p:panel>
        <f:facet name="header">
          testing
        </f:facet>
        <div class="paddingForPanel">
          <h:outputText value="#{testing.msg}" escape="false"/>             
        </div>
      </p:panel>            
    </div>
  </h:body>
</HTML>

这是我的测试文件.

public void getMessage() {      
    this.msg = "haha";
}

private String msg;
public String getMsg() {
    return msg;
}
public void setMsg(String msg) {
    this.msg = msg;
}


上面的代码无法打开新的选项卡/窗口,我尝试如下操作,成功在新选项卡中打开新页面,但味精为空,当我调试时,它成功调用了监听器getMessage,我想知道为什么在msg.xhtml页面中味精为空? 预先感谢....


the code above fail to open a new tab/window, I try to do like below, it success to open the new page in new tab but the msg is empty, when I debug, it got success call the listenner getMessage, I wonder know why the msg is empty in the msg.xhtml page? Thanks in advance....

<p:commandLink actionListener="#{testing.getMessage}" oncomplete="window.open('msg.xhtml')">broadcast Msg</p:commandLink>

推荐答案

<p:commandLink>有一些ajax问题,请改用<h:commandLink>.

<p:commandLink> has some ajax issues, Use <h:commandLink> instead.

 <h:commandLink actionListener="#{testing.printMessage}" action="/Msg.html" target="_blank">get Msg</h:commandLink>

<p:commandLink>更改为<h:commandLink>,您的代码可以正常工作.

changed <p:commandLink> to <h:commandLink> and your code is working fine.

这篇关于p:commandLink无法在新窗口/选项卡中打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆