I joined a project which uses spring framework and all the calls are made by ajax requests and the redirection after success is defined in the view itself and passed to the ajax JS function through a hidden input (so the return ModelAndView at the end of every function in the controller doesn't have any effect). I feel it messes up the code somehow Am I right? Still I think this was done because they wanted to get the benefits of having restful app with CRUD mapped to post,get,put,delete but eventually they lost the ability to redirect from the controller itself.
Well the pattern which i generally use and recommend is the following:
Advantages with this approach:
Ajax:
HTML:
I just spend little time with Spring so I can not judge on everything. It may be that the development pattern itself of spring causes you to feel uncomfortable. In Java you are used to feel in OOP. The general concept of MVC gets mixed with html AJAX etc. Kept in mind that you have a server/client architecture and you would like to have all components distinct. Thats something that can be very well done with the Google Web Toolkit.
So what I read is that you make a browser refresh. Where is the benefit of AJAX if you make a refresh? Not knowing your application but knowing that some things can not be done so easy in Java (if you are adapting foreign code), you are doing right and should think over your program sequences.
The only diffrent way besides the AJAX HTML i can think of is a Socket connection that can be done with either an ActiveX Component, Flash or the html5 Websockets. But thats generally not what you use for simple forms.
BTW. the GET string is known to be maximum around 2000 chars but a bit faster in execution because you don't send headers like POST.
And in my oppinion: Regarding to performance, its better to have less requests and spit out more html first than try and force yourself to just make ajax everywhere. Since you lost your SEO advantage anyway.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With