我正在使用 JSF 2.0 构建一个调度应用程序,用户可以在其中将项目添加到日历中,然后编辑这些对象。
我广泛使用 AJAX 来防止页面刷新。
我遇到的问题是从使用 AJAX 调用的函数中获取返回值。
<!-- ... form to fill -->
<h:commandButton value="Insert">
<f:ajax execute="formField1 formField2..."
listener="#{myBean.insert()}" onevent="processSave"/>
</h:commandButton>
这成功调用了我的 JavaScript 函数processSave()
.
myBean.insert()
返回id
数据库中新插入的行的
public String insert() {
//... inserting data into database
id = {id from database is obtained here}
System.out.println("I have the ID here : " id); //this works
return id;
}
我一直在尝试从 JavaScript 中的响应对象中获取此内容processSave()
功能。
processSave(data) {
if(data.status == "begin") {
// ation done here
} else if(data.status == "complete") {
// more actions done here
} else if(data.status == "success") {
//I am trying to get the ID here
//I've tried looking into data.responseXML, but to no avail.
}
}
使用当前技术我正在尝试的事情可行吗?
我认为可以使用以下方法更新页面中的字段render
AJAX 调用的组件,然后使用 Javascript 去获取值。但我想这不会那么干净吗?
谢谢你!