I was hoping I could get some opinions or critiques on an idea I had to make ajax forms easier to manage. Obviously the easiest thing to do is have no ajax specific handling at all, and send the entire response back to the client which will then selectively update parts of the page through a framework like JQuery. This however is a major bandwidth waste and sort of defeates the purpose of ajax to begin with.
Traditionally I have had code in my action beans that determine if the request was ajax, and I would respond accordingly with a smaller fragment jsp. However this gets verbose when you are dealing with lots of different types of ajax updates and the fragments need to work correctly with the action bean. This is what I've been traditionally using. I haven't been a fan of json responses because thats even more work on the client side to repopulate the page. I like the simplicity of using jsps and the action bean, and replacing content on the front end with JQuery. However I was thinking of a different approach, which can still keep the action bean in the dark about whether a request was ajax or not, and still return a fragment page without all the work. What I envisioned was a generic AjaxForwardResolution class, which first determines if the request was ajax or not. If not, it returns the jsp just like the ForwardResolution would. If it was an ajax request however, it would look for parameters passed in with the form that contains the ids of elements that should be returned. It would then strip those elements out of the full response and put them in a smaller fragmented response. So for example, a form might look like this: <s:form> <s:input type="hidden" name="ajaxResponse" value="messages" /> <s:input type="hidden" name="ajaxResponse" value="content" /> </s:form> An action bean would look like this: return new AjaxForwardResolution("/WEB-INF/jsp/someResponse.jsp") And the response would look simply like this (for ajax requests) <html> <div id="messages">...</div> <div id="content">...</div> </html> There is the question of performance now that the server needs to parse these elements out of the response string. And it is wasteful that the other parts of the page have been rendered unnecessarily. But this would make any ajax call trivial if you have a generic client submit method to handle all responses. Any thoughts about this, or has anyone tried or worked on a different approach? -- View this message in context: http://old.nabble.com/Making-ajax-responses-easier-with-an-AjaxForwardResolution-tp32960604p32960604.html Sent from the stripes-users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure _______________________________________________ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users