[英]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.