2011-04-07 49 views
2

我正在使用JSF 2.0构建一个调度应用程序,用户可以将项目添加到日历中,然后编辑这些对象。使用JSF 2.0 Ajax响应从bean函数访问返回值?

我使用的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; 
} 

我一直在试图从processSave()函数中的JavaScript响应对象得到这个。

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. 
    } 
} 

是我正在尝试使用当前的技术?

我认为这将有可能使用AJAX调用的render组件更新页面中的字段,然后使用Javascript去获取该值。但我认为这不会干净?

谢谢!

回答

4

这是可能的。用primefaces更容易完成。

请按照this的例子,你可能会发现一些有用的东西。

+2

是否有可能没有primefaces? – angelcervera 2012-08-11 19:34:56

+0

我有完全相同的问题。你有没有设法解决它? btw primefaces链接被打破。 – 2014-06-11 12:40:44