在JSF 2.0应用程序中,如何从ManagedBean获取大量数据到我的javascript代码中?

时间:2020-11-30 09:22:30

I have a JSF 2.0 app where I need to get from the server side ManagedBean a huge amount of data to load into a multidimensional array of about 7000 javascript objects for graphic display. Ultimately these objects will be edited by the app and returned to the server for storage back in the db they came from, so transport in both directions would be needed.

我有一个JSF 2.0应用程序,我需要从服务器端ManagedBean获取大量数据,以加载到大约7000个javascript对象的多维数组中进行图形显示。最终这些对象将由应用程序编辑并返回到服务器以便存储在它们来自的数据库中,因此需要在两个方向上进行传输。

The usual ways to get and set data via hidden h:inputText items wont handle this sort of volume. I also tried to do an ajax call from my client side code but I cant figure out what url to use to get to my session's ManagedBean. It seems like this should be possible somehow ...

通过隐藏的h:inputText项获取和设置数据的常用方法不会处理这种卷。我还尝试从客户端代码执行ajax调用,但我无法弄清楚用于访问会话的ManagedBean的url。似乎这应该是可能的......

1 个解决方案

#1


1  

you can use servlets for retrieving and processing data with jquery ajax

您可以使用servlet通过jquery ajax检索和处理数据

Servlet class :

Servlet类:

    @WebServlet("/jsonservlet/*")
    public class JSONServlet extends HttpServlet {




        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException{

           //use any json library ( I recommended gson library)

            response.setContentType("application/json");            

           response.getWriter().write(jsonData)
        }
    } 

now you can make ajax call to this servlet using jquery to retrieve the json returned data

现在,您可以使用jquery对此servlet进行ajax调用,以检索json返回的数据

$.ajax({
        url: "jsonservlet",
        type: 'GET',
        dataType: 'json',

        contentType: 'application/json',
        mimeType: 'application/json',

        success: function (data) {
            //here you can populate your javascript array 
        },
        error:function(data,status,er) {
            alert("error: "+data+" status: "+status+" er:"+er);
        }
    });

#1


1  

you can use servlets for retrieving and processing data with jquery ajax

您可以使用servlet通过jquery ajax检索和处理数据

Servlet class :

Servlet类:

    @WebServlet("/jsonservlet/*")
    public class JSONServlet extends HttpServlet {




        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException{

           //use any json library ( I recommended gson library)

            response.setContentType("application/json");            

           response.getWriter().write(jsonData)
        }
    } 

now you can make ajax call to this servlet using jquery to retrieve the json returned data

现在,您可以使用jquery对此servlet进行ajax调用,以检索json返回的数据

$.ajax({
        url: "jsonservlet",
        type: 'GET',
        dataType: 'json',

        contentType: 'application/json',
        mimeType: 'application/json',

        success: function (data) {
            //here you can populate your javascript array 
        },
        error:function(data,status,er) {
            alert("error: "+data+" status: "+status+" er:"+er);
        }
    });