Skip to Content

In my previous blog titled “Light weight portal apps using jQuery and DataTables”, I described how a jQuery plugin can make the table UI element more intuitive and agile. In this blog, I will elucidate what is possible when Portal eventing framework can be simultaneously used along side jQuery.

jQuery gives all the freedom and flexibility where other established frameworks/technologies fall short, specially while implementing AJAX calls. And when jQuery can be used in co-ordination with portal eventing EPCF framework , the possibilities increase many fold.

One the one hand, you can create intuitive dashboard feel applications, that could broadcast events to other iviews on the same page (courtesy of EPCF portal eventing), on the other, jQuery AJAX calls can be easily implemented from within each iview (the whole page ever refreshing at all). A basic example for jQuery AJAX call can be as simple as fetching product details upon product name/ID click.

jQuery has inbuilt JSON parser available with $.getJSON AJAX function, that can read JSON objects and arrays. This comes pretty handy when querying database.

Since getJSON() is asynchronous function call, we have to set the async attribute to false in the ajaxSetup function.

The errors in the AJAX call can be trapped using the “error” function inside ajaxSetup.

Here is the sample code:

$.ajaxSetup(});      

     if(!(null == request.getParameter(“url_parameter”))){

                  // prepare json

                  try {

                        HttpServletResponse response1 = request.getServletResponse(true);

                        PrintWriter out = response1.getWriter();

                         response1.setContentType(“application/json”);

                       if(!objectArrayList.isEmpty()){ //objectArrayList to be sent as a result of AJAX request

                              JSONArray jsonArr = new JSONArray();

                              jsonArr.put(objectArrayList); // Converts ArrayList to JSON array

                              out.print(jsonArr);

                        }

                        out.flush();

                  } catch (IOException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                  }

            }

Here JSON API is used to convert the array list of objects into a JSON array. Firebug tool comes handy while debugging the application

/wp-content/uploads/2011/02/firebugtool_81310.jpeg

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply