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

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

问题描述

我正在尝试创建一个链接以在不同的窗口/选项卡中打开一个新页面,并显示来自支持 bean 的一些消息,但未能做到,不知道为什么?

这是我的 xhtml 文件:

<h:body><h:form id="form66"><p:commandLink actionListener="#{testing.getMessage}" action="msg.xhtml" target="_blank">获取消息</p:commandLink></h:form></h:body>

这是我的 Msg.xhtml 页面

<h:头><title>测试</title></h:head><h:body><div class="div"><p:面板><f:facet name="header">测试</f:facet><div class="paddingForPanel"><h:outputText value="#{testing.msg}" escape="false"/>

</p:面板>

</h:body></HTML>

这是我的testing.java

public void getMessage() {this.msg = "哈哈";}私人字符串味精;公共字符串 getMsg() {回消息;}公共无效setMsg(字符串味精){this.msg = msg;}


上面的代码无法打开新选项卡/窗口,我尝试像下面那样,在新选项卡中打开新页面成功但味精为空,当我调试时,它成功调用监听器 getMessage,我不知道为什么 msg.xhtml 页面中的 msg 是空的?提前致谢....

<p:commandLink actionListener="#{testing.getMessage}" oncomplete="window.open('msg.xhtml')">广播消息</p:commandLink>

解决方案

有一些 ajax 问题,请改用 .

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

更改为 并且您的代码运行良好.

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?

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>

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>

here is my testing.java

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

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


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> has some ajax issues, Use <h:commandLink> instead.

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

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

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

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆