hen*_*eng 20 jsf commandlink primefaces jsf-2
我正在尝试创建一个链接,在不同的窗口/选项卡中打开一个新页面,并显示一些来自支持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>
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的testing.java
public void getMessage() {
this.msg = "haha";
}
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码无法打开一个新的选项卡/窗口,我尝试像下面这样做,它成功在新选项卡中打开新页面但msg为空,当我调试时,它成功调用了监听器getMessage,我想知道为什么msg.xhtml页面中的msg为空?提前致谢....
<p:commandLink actionListener="#{testing.getMessage}" oncomplete="window.open('msg.xhtml')">broadcast Msg</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
nen*_*eni 18
<p:commandLink>有一些ajax问题,请 <h:commandLink> 改用.
<h:commandLink actionListener="#{testing.printMessage}" action="/Msg.html" target="_blank">get Msg</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
改变<p:commandLink>对<h:commandLink>你的代码是工作的罚款.
两者都不起作用,所以问题不在ajax中。p:commandLink的target属性中的问题不起作用...
<p:commandLink value="New Window" ajax="false" target="_blank" action="test"/>
<p:commandLink value="New Window" target="_blank" action="test"/>
Run Code Online (Sandbox Code Playgroud)
所以我们必须使用
<h:commandLink value="New Window" target="_blank" action="test"/>
Run Code Online (Sandbox Code Playgroud)
小智 5
我这样做:
<p:commandLink id="link" actionListener="#{testing.getMessage}"
oncomplete="popupwindow('msg.xhtml', 'newwindow');" >
<h:outputText value="broadcast Msg" />
</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
使用一些 javascript:
<script type="text/javascript">
function popupwindow(url, title) {
window.open(url , title, "toolbar=no, scrollbars=yes, resizable=yes, top=170, left=170, width=800, height=600");
}
</script>
Run Code Online (Sandbox Code Playgroud)
在这个例子中你打开一个新窗口,希望它有帮助!
| 归档时间: |
|
| 查看次数: |
79964 次 |
| 最近记录: |