Hi Folks,
We need some input on what is a good design pattern on using AJAX in a Java application.
Consider a simple scenario:
- User clicks a button which sends a request to a Java method to fetch data from DB.
- Java object is returned by method and needs to be converted into a HTML table.
- HTML table is shown on JSP.
What we currently do:
- On a JSP page, user clicks "Show Users" button
- Button using Prototype.js calls a "middleman" JSP which forwards the request to the Java method to get the data from the DB.
- The method returns the Java object to the "middleman" JSP which converts the Java object into HTML (since the AJAX call from the calling JSP won't be able to handle the Java object directly).
- The HTML is then returned to the Prototype call which updates the div on the calling JSP.
Our concerns are:
- We would like to keep the separation of business/presentation logic and would prefer no HTML/JavaScript code inside our Java methods.
- Keeping (1) in mind, is having a "middleman" JSP an OK way to do this? Or should we return the Java object as XML/XSLT to the AJAX request?
- The above way we're doing has very little JavaScript and works in all browsers.
- We looked at some other packages - DWR, GWT, but either there was too much dependency on JavaScript or required UI components to be present in the Java classes.
Is our way of doing things above OK? Or is there another preferable way?
Any help/thoughts would be appreciated.
Thanks,
SP