Question

I use RichFaces to develop some web pages, basically I'd like to display a list of my data with DataTable. But my manage bean will take a long time to obtain resource data, which blocks the web page display.

My goal is to dynamically display them, First display the web page (maybe no data yet), then once my manage bean reads one new data, it displays this as a new row in my DataTable, any idea how can I do that? or maybe a similar example is appreciate.

Was it helpful?

Solution

Load the page then fetch data using JavaScrip via an Ajax call. Ajax is very easy to implement using jQuery.

jQuery Ajax Documentation

Example: Untested!! But its something like this..

<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script>
// Run on page load
$(function() {
    $.ajax({
        url: "getMyData.html",
        type: "GET"
    }).success(function(data) {
      // My data is in "data", if it is html then
      $("#myDiv").html(data);
    });
});
</script>
</head>
<body>
    <h1>Hello</h1>
    <div id="myDiv"></div>
</body>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top