【发布时间】:2013-12-12 14:32:46
【问题描述】:
我正在努力将 Primefaces bean 属性直接发送到 javascript,以便打开新页面并将 bean 属性的内容写入新页面。
我正在使用 Primefaces 4.0。
我有一个这样的命令按钮:
<p:commandButton id="buttonId" update="buttonId, otherComponentId"
value="press me" process="@this" actionListener="#{homeController.myMethod}"
oncomplete="handleComplete(xhr, status, args)">
</p:commandButton>
在handleComplete javascript 函数中未定义参数,但未定义xhr 和状态。 javascript函数定义:
function handleComplete(xhr, status, args){
var w = window.open();
w.document.open();
alert(xhr.responseText.substring(100));
alert(status);
alert(args);
var d = '<head></head><body>'+ args.firstParam +'<body>';
w.document.write(d);
w.document.close();
}
第一个警报它给了我页面,第二个警报解析错误, 错误是:Uncaught TypeError: Cannot read property 'firstParam' of undefined
我想在 args 中传递一个这样的字符串:
public String MyMethod() {
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("firstParam", "my string");
return "";
}
并使用 args.firstParam 在 javascript 中访问它。
该方法被调用,(我有一些可以工作的打印屏幕。)
我必须尝试这种方式而不是将文本设置为
<h:outputText id="myText" escape="false" rendered="true"
value="#{homeController.property}" />
然后获取该元素的innerHTML,因为我将使用innerHTML 得到的内容与bean 中的字符串变量不同。这种方法有效,但不是我想要的。我想知道为什么 args 对象是未定义的,或者我怎样才能从 javascript 中获取可管理的 bean 属性。谢谢。
【问题讨论】:
标签: javascript ajax primefaces