简体   繁体   English

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

[英]In a JSF 2.0 app, how can i get a huge array of data into my javascript code from the ManagedBean?

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

The usual ways to get and set data via hidden h:inputText items wont handle this sort of volume. 通过隐藏的h:inputText项获取和设置数据的常用方法将无法处理这种体积。 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. 我也尝试从客户端代码进行ajax调用,但是我无法弄清楚要使用哪个URL来访问会话的ManagedBean。 It seems like this should be possible somehow ... 看来这应该是可能的...

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);
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从JSF 2.0中的javascript获取元素 - How to get element from javascript in JSF 2.0 如何让 JSF 2.0 将 JS 包含为“应用程序/javascript”而不是“文本/javascript” - How can I get JSF 2.0 to include JS as 'application/javascript' instead of 'text/javascript' 如何在JavaScript中使用JSF 2.0值? - How can I use JSF 2.0 values with JavaScript? Javascript变量值从ManagedBean属性获取 - Javascript Variable Value Get From ManagedBean Property 如何在JavaScript中获取包含大量数字的精确值字符串? - How can I get exact value string of huge numbers in JavaScript? 如何从会话中获取JavaScript中的列表(包含大量数据)? - How to get the List(contain huge data) in javascript from session? 如何确定我的React Native应用程序是否是JavaScript代码的调试或发布版本? - How can I determine if my React Native app is a debug or release build from JavaScript code? 如何在JavaScript数组中优化代码? - How can i optimize my code in a JavaScript array? 如何从我的 express 应用程序获取数据到我的前端组件(在 React 中)? - How can I get data from my express app to my component in the frontend(which is in React)? 如何从 RESTful 接口获取信息并在我的 Javascript 代码中使用它? - How can I GET information from a RESTful interface and use it in my Javascript code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM