View Full Version : Extjs-SpringMVC-Hibernate

30 Jan 2012, 9:15 PM
I have started working on an email-SMS application using extjs-spring-hibernate(Worked with servlets previously but was suggested for this by forum members). But apart from Loaine's example there is not much for reference(that puts me in a dilemma if I am going the right way as not much work done unlike Ext .net for which many examples are available). I would like a simple example with explanation regarding configuration and JSON handling using spring hibernate to get started.
Any pointers or help would be appreciated.


30 Jan 2012, 11:10 PM
I'm doing such things... but unfortunately I haven't the time building something like a tutorial yet. I suggest that you have to look for configuration of the jackson view (json encoding/decoding). The biggest deal is, that you have to put the jackson lib in the classpath when you are using the mvc:annotation based config.

With Spring-MVC Annotations the most things are very easy to configure. What you have to had in mind is, that Ext is using a wrapping data-exchange model... means that you have to capsule your payload in an object or hashmap with a property "data" and send another property "success: true" if everything is fine. Currently I'm doing this with two wrapper objects for SuccessResponse and ErrorResponse (including the error-map). Same problem appears when you're receiving data from Ext on the server part. In Spring's Controller you should have a method like:

public @ResponseBody ExtResponse someMethod(@RequestBody ExtPayload data) {
//make some stuff and return the object(s)...

Here the ExtPayload Object is the clue only wrapping the "data" property again. I currently have extended the BeanDeserializer of Jackson to enable it skipping the first wrapping object. I don't know exactly, but this may unnecessary if you're using Spring 3.1, because there is some configuration for the jackson-view enabling it to skip the first wrapping object of json data. When you do this - it's easier again, because you only have to put your real entity (Classes with JavaBean Convention) you want to populate in the method parameter list with a @RequestBody Annotation.

If you want everything more dynamically you can consider allways using Map<String,Object> structures...

You also should have something in your controller class to show the jsp (by returning a string to the jsp-view you want to use) containing the script-imports for ext and the Application build-up (Ext.application... building a viewport,...).


30 Jan 2012, 11:26 PM
Thanks a lot börn for the prompt reply.
Though I did not get much out of it,but it helped me in having a good perspective(I was not aware of Jackson view and I am studying SpringMVC annotations).
As far as JSON returning is concerned I am aware of the reader and writer in extjs that can be used in the View part.
For example like this,where data will be the root of the returned json.

var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'id',
root: 'data',
messageProperty: 'message'

Also,if you find time please share the details regarding the same.I don't expect the entire code but something that will help to start in the right direction with SpringMVC-extjs-Hibernate.


30 Jan 2012, 11:42 PM
I'll have a look ;) ... i'm already planning some things in this direction for my company - and after doing that, I think I could give some examples for configuration and controller logic and how it works altogether.

When using Hibernate - you should be aware of your proxies and lazy-loading. Because when serializing into json you mostly don't have a hibernate session anymore. Because of that you should load all your data you want to send to the view in your controller before. The easiest way is then to use some kind of DTOs - putting your data you want to send to the client in it and let it serialize with jackson (but this is really annoying). A better way is to use a jackson module (hibernate-module) which enables jackson to recognize hibernate proxy objects and strips away all lazy and not yet initalized properties with null values - so you don't get any more lazy-initialization-exceptions when serializing to json ;)

30 Jan 2012, 11:49 PM
Well,I will surely give it a try(nothing to loose). I will wait for your reply over the same.Hopefully you get it done soon.;):)
Let me know if you have anything up,through the thread or private message means.If you have any website share the link,I would follow it.