wood burning stoves 2.0*
The moose likes Spring and the fly likes How design controllers for use with AJAX? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How design controllers for use with AJAX?" Watch "How design controllers for use with AJAX?" New topic
Author

How design controllers for use with AJAX?

Daniel Näslund
Greenhorn

Joined: Jul 14, 2009
Posts: 11
I want to write a web 2.0 app, get wealthy and live happily ever after. What stands in my way is some understanding of how to design the Spring controllers for use with my AJAX framework.

I have tried the simple DOJO decorations available through Spring JS (DatePicker and Textbox). They work well with and without Javascript enabled. But I want more! I want 'bread crumb trails', advanced datagrids, dynamic diagrams and such. Does Spring JS expand to more than just client-side validation? I haven't found any good documentation yet.

Perhaps Spring JS is not the right design choise either. I want to have clear separation between the different layers of the app and Spring JS is a glue that makes the view layer dependent of Spring. So I was thinking: I use DOJO and send XML or JSON to my controllers using the RESTful approach that is supported through Spring 3.0. But then I need some controllers that return XML or JSON and some that return views, i.e. JSP-pages. This can get a bit messy. I was thinking of using one package for controllers returning JSP pages and one for controllers returning XML or JSON. Is that the way to do it?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's *one* way to do it--is it the "right" way? Depends. I tend to cluster classes by application functionality, which is independent of the view technology.
Daniel Näslund
Greenhorn

Joined: Jul 14, 2009
Posts: 11
David Newton wrote:That's *one* way to do it--is it the "right" way? Depends. I tend to cluster classes by application functionality, which is independent of the view technology.


Thanks for your answer. I can see the advantages in keeping everything associated with one application functionality together.

Another question, but still on the topic. I saw that you were proficient in Struts so maybe this can be generalized to any MVC framework: When using AJAX calls, how do you give feedback for illegal input, that is form:error and such? If it's a simple textbox it's easy but what about input in an complex datagrid for instance? Do you write your own tags for it or use the ones provided by the framework? Perhaps setting my own error attributes is an option, that is, not using the MVC framework for error handling at all. But it seems as a waste of time to reimplement something that already exists.

In short: Is there some general solution to the problem of validating complex AJAX widgets?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

In short: no; it'd depend on the widget, the framework, application requirements, etc.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How design controllers for use with AJAX?
 
Similar Threads
Struts and Ajax
jsp page table has right click disabled. Why?
how to design a Web App in Spring: why not web-page driven design?
JSON with Ajax.
json and jsp?