Skip to main content

Posts

Showing posts from October, 2008

Maintaining session when using DWR

DWR ( Direct Web Remoting ) provides an amazingly convenient approach to AJAX and the best thing is that it is so easy to implement. When I was using DWR, I got a little confused about maintaining session, since most of the examples available used POJO/bean to implement java code which was then sent back to javascript. In my application, an arraylist (formList) was maintained in session. I had to use DWR to show the details about this arraylist on the JSP. In the java class being used by DWR, I needed to pass the session from calling JSP. DWR gives this in a surprisingly easy way! JSP snippet: <button onclick="getProperties(id);">Click! </button> In the javascript: function getProperties(id) { DwrUtility.getDetails(paneId, function(data) { dwr.util.setValues(data); }); } In the Java class: public String getDetails(String menuId, HttpSession session ){ int paneId=Integer.parseInt(menuId); ArrayList formList=(ArrayList)session.getAttribute("FormsList")