我试图创建一个链接,在新的窗口/标签页中打开一个页面并显示一些来自后端bean的消息,但无法实现,想知道原因是什么?
这是我的xhtml文件:
<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页面
<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>
这是我的testing.java文件
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页面中消息为空?
提前致谢....
<p:commandLink actionListener="#{testing.getMessage}" oncomplete="window.open('msg.xhtml')">broadcast Msg</p:commandLink>
commandLink
的第一个版本中设置ajax="false"
。 - partlov