I'm developing a webapp with Hibernate+Spring 3 (Spring MVC, JSP): I'd like to create some divs with AJAX style (i.e. no need to refresh all the page, independent update of each div).
I'd like a good advice about which AJAX library to use (in conjunction with Spring 3 MVC + JSP) and, if possible, where to find some code snippets.
I know very little of AJAX libraries, JSONs and how to integrate them, but I have good knowledge of Javascript and Spring (and how callbacks work). I'd like to write as less code as possible, particularly in the jsps.
My Webapp will display an updated (every 5 minutes) POJO in a div and perform some operations between different domain objects in the other div when user press a button.
This is correct use JQuery
Here
http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
you can find working examples to use Jquery+JSON+Spring MVC.
and this question can help you with server side configuration:
JQuery, Spring MVC #RequestBody and JSON - making it work together
I would suggest jQuery. It is very easy to use and has very good ajax support.
In addition to that it has quite a lot of plugins and components.
Related
I am currently studying Java EE with Hibernate for a project. In The Web App I am creating I am planning to Ajaxify page contents, and Site wide audio player(Which I think would be implemented using AJAX).
I am using a JSP based MVC, no frameworks, Just Java EE and Hibernate. And I've heard that I need to use a Framework like JSF to be able to AJaxify may web-app. How true is this? Do I really need to learn JSF or other frameworks to be able to Ajaxify my web app? As much as possible I do not want to learn a new framework for now since it is a big learning curve. but if there's no other way to Ajaxify my web app, I'll study a framework.
You don't have to adopt any framework to use partial page updates and similar, you can construct and send requests "manually" with JavaScript, but this is much more tedious then using a framework like JSF, maybe coupled with a component library like primefaces.
EDIT: you can find an abundance of examples of ajax capabilities in the primefaces showcase. Primefaces uses JQuery internally.
EDIT2: I have found some resources on how to dispatch ajax requests with JQuery from a JSP page (I assumed that using JSP was almost equal to not using a framework ;)): here and here. I hope this is what you were looking for.
To add on #Kostja's answer -
I totally agree with him, with Ajax you just need to have a servlet to handle the HTTP requests, and proper JavaScript code.
Besides JSF,I would also consider to look at Apache Wicket - you can read here how Wicket handles Ajax.
The reason I'm suggesting Wicket is that it's more comfortable to some developers to work with somewhat more "component oriented" (swing-like) framework.
Hello I am using spring mvc and my page consist of 2 columns left and right. I want that left side is rendered from one controller and right side is rendered another one. How to accomplish that. Fore example in the right side here is login form which renders from LoginController but the left side changes all time. How to accomplish it with spring mvc framework.
thanks in advance.
Spring MVC is not inherently a component-oriented framework, like you seem to want. Some different approaches that might suit you
Client-side aggregation. Load your different "components" (left, right) using AJAX
Using some more template/component-oriented rendering framework. I like Apache Tiles and breaking out logic in Preparers (analogous to Controllers in Tiles). Or you can use JSF 2. I wrote a bootstrap/tutorial on Spring MVC 3 and JSF 2 a while back that might be interesting for you.
Go full-on with a component-oriented framework like JSF 2, Tapestry or Wicket.
There are various ways to implement this. What are your exact requirements? You can try:
Portlets - render two portlets, each is rendered separately. Probably an overkill if this is needed only in this one place.
AJAX - Render an empty page first and fetch both views separately using AJAX. See $.load().
<iframe/> - embed iframes with two different target URLs.
Use component-oriented framework (I personally like Wicket).
None of these approaches are tied Spring MVC or even Java.
I have some knowledge about Flex and Java EE, they are good for web application development. Anyway when I try to write a typical web page that is based on HTML/CSS/Javascript, I think I should take a look at some new program language/framework.
I heard much good news about grails and finally decided to learn it instead of python, ruby, scale… But I still don’t have an overview of the whole structure. Grails is a backend framework like php, jsp, jsf right? So that probably means, it’s a replacement of Java EE in backend, then how about the frontend (need ajax functionality), what are people using with grails?
thanks
Grails is not a replacement, it is an abstraction around the tradition Java EE stack and some extremely popular libraries like Spring and Hibernate, that allows you to go faster by using "convention over configuration".
One component of Grails is GSPs, groovy server pages, which is a front end technology, the V in the MVC (Model View Controller) paradigm. You also have Domain Objects, which are the M (Model), and Controllers, which are the C. Grails also has Services which are best put into the M category (IMHO) of the MVC paradigm. So the Model arrangement in Grails gives you relatively easy persistence (using hibernate under the covers), the Services give you great reusability in your business and transactional logic, and the Controller simply invoke the right logic for a given request, and return the response.
One part of that response is what gets displayed on the screen. In a simple webapp, GSPs fill that role -- the controller tells the browser to render a specific GSP which has data bound to it from the service method that was invoked in the controller. However, it is easy to have the controller return json, so if the endpoint bound to the controller is an ajax request, the client can handle the response itself.
You can use any front end technology you want in a grails app. The default is GSPs, which is an extension of JSPs, which are part of the traditional java stack, but you can use jQuery, Sencha, Sproutcore, Backbone, anything you want. You would have one GSP in that case which bootstraps your javascript code, and the rest would be handled by the client application.
Grails is a web framework and is not just a backend framework. It supports both JSP and GSP ( Groovy Server Pages) for views.
If you plan to use Ajax functionality, you can make use of one of many javascript frameworks available. You can also go ahead with Flex (since you already know it) or use a javascript framework like ExtJs, Dojo, YUI etc...
I new on Struts2, and i need to do some AJAX call to the server.
I tried to search some tutorial, but expect roseindia ones, i don't find nothing.
Also, i don't understand if Struts2 implements natively Ajax or if i must use it with some library (like Dojo or Jquery?).
Also, can you give to me some good tutorial?
Cheers
Struts2 is an MVC framework for building server-side web applications and Ajax is a concept that exists within the client-side of things. From the server's perspective, it just needs to respond to an HTTP request (which happens to come from JavaScript for Ajax).
Therefore, Struts2 does not "implement Ajax." You'll need to use JavaScript (or a JavaScript framework like jQuery, Dojo, etc.) as you mentioned.
You can use these in Struts2 just as you would in any web project, by including the necessary JavaScript and CSS files, or you can use a Struts2 plugin (there are plugins for both previously mentioned libraries).
I'm pretty sure that the jQuery and Dojo plugins contain tag libraries for doing Ajax.
we use the struts 2 json plugin for returning json from struts actions.
on the client side, you'll likely want to use a javascript framework like jQuery to issue your ajax calls and then handle the json response.
I am new to Spring as well as Dojo. I need to use Dojo with one of my mvc project in Spring 3.0
I came accross below link which talks about using spring-js with Dojo.spring-js part of spring framework?
http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch11.html
I could not really follow that link, is there any step by step tutorial which will show me how to use dojo with spring framework 3.0 ?
I need to start with simple things with Dojo like client side validation of forms.
Thanks in advance!
This is a tough question to answer, because it turns out you don't really need to worry about how Dojo and Spring interact. Your client and your back end server are completely unrelated until you decide to send data back & forth.
So for dojo, you probably want to look at how to use some of the form validation. Take a look at this link for some help on that:
http://o.dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/form-validation-specialized-input
Once you have some validation in place, your form can use the normal form post to post your data to the server, same as how you would do it without javascript.
On the other hand, if you want to add some nice Ajax to your application, take a look at this link which explains how to implement Jackson marshalling/unmarshalling to send JSON data to Spring & handle responses correctly.
http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
Spring Roo uses Dojo, so you can create a Roo Project and have a look like they did it.
For Spring, You can follow this tutorial (Its the most compact and covers all basics):
http://www.tutorialspoint.com/spring/index.htm
And for Dojo The best tutorial is at: http://dojotoolkit.org/features/desktop
(in Create Beautiful User Interfaces subheading youll find all the APIs and their examples)
Its the way I learnt it. :)
Cheers