使用JSF 2.0 Ajax响应豆函数访问返回值? [英] Accessing return value from bean function using JSF 2.0 Ajax response?

查看:101
本文介绍了使用JSF 2.0 Ajax响应豆函数访问返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我builiding使用JSF 2.0,用户可以将项目添加到日历然后编辑这些对象调度的应用程序。

I'm builiding a scheduling application using JSF 2.0 where users can add items to a calendar then edit those objects.

我使用AJAX相当广泛,以保持页面的清爽。

I'm using AJAX quite extensively to keep the page from refreshing.

我遇到的问题是要获得从使用AJAX调用函数返回值。

The problem I am having is to get a return value from the function that is called using AJAX.

<!-- ... form to fill -->
<h:commandButton value="Insert">
   <f:ajax execute="formField1 formField2..." 
    listener="#{myBean.insert()}" onevent="processSave"/>
</h:commandButton>

这成功调用我的JavaScript函数 processSave()

This successfully calls my JavaScript function processSave().

myBean.insert()返回 ID 在数据库中新插入的行

myBean.insert() returns the id of the newly inserted row in the database

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响应对象得到这个。

I've been trying to get this from the response object within JavaScript in the processSave() function.

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

是什么,我想有可能使用目前的技术?

Is what I am trying possible using the current technologies?

我认为这将有可能在使用AJAX调用的渲染组件更新页面的字段,然后使用JavaScript去获得的价值。但我想这不会是干净?

I think it would be possible to have a field in the page updated using the render component of the AJAX call, then use Javascript to go get the value. But I'm thinking this wouldn't be as clean?

感谢您!

推荐答案

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

It is possible. And more easily done with primefaces.

这个的例子,你可能会发现一些有实用

Follow this example, you may find something useful there.

这篇关于使用JSF 2.0 Ajax响应豆函数访问返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆