gpt4 book ai didi

jsf - p :commandLink fails to open page in new window/tab

转载 作者:行者123 更新时间:2023-12-02 01:30:36 27 4
gpt4 key购买 nike

我正在尝试创建一个链接以在不同的窗口/选项卡中打开新页面并显示来自支持 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>

这是我的测试.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页面中的msg为空?提前致谢....

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

最佳答案

<p:commandLink>有一些ajax问题,使用<h:commandLink>相反。

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

已更改<p:commandLink><h:commandLink>并且您的代码运行良好。

关于jsf - p :commandLink fails to open page in new window/tab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14724518/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com