Book Review: Enterprise Application Development with Ext JS and Spring

I was asked to review “Enterprise Application Development with Ext JS and Spring” book by Packtpub guys and here is my review on the book. Actually now I am working on a project which is being developed using ExtJS and I thought of buying this book. But surprisingly on the very next day I was asked to review this book and gave me the ebook :-).

Book WebSite URL: http://www.packtpub.com/enterprise-application-development-with-extjs-and-spring/book

Personally I like the books which explains any technology/framework/library by taking a sample application and building the application progressively chapter by chapter. Enterprise Application Development with Ext JS and Spring book followed the same pattern and covered all levels of project development using Spring and ExtJS completely starting from Development environment setup with NetBeansIDE, Maven and Glassfish server to writing unit testing and building production ready ExtJS code using SenchaCmd.

We can find plenty of examples on Spring and ExtJS on the web, but the real challenge is stitching them together and building a real application. With this book you can build the bits and pieces (core services, UI components etc) and integrate them by following the step by step instructions as described in the book and finally create a working application.

The sample application “Task Time Tracker” is developed using Spring, JPA/EclipseLink and ExtJS. Each of these technologies are themselves huge topics and one can’t cover all these topics indetail .
But the author did a fantastic job of explaining all the concepts using to build the application as much as possible.

Highlights:

  • Clear development environments steps for setting up JDK, NetbeansIDE, Maven and Glassfish, even novice users can get it done by simply following the steps.
  • You can build the application progressively chapter by chapter with proper flow, there no jumps or deviations from sequence.
  • Very detailed explanation on creating RESTful services using SpringMVC with JSON support.
  • Author explained writing JUnit tests for repositories and services with complete code examples encouraging to follow TDD.
  • Explained ExtJS MVC philosophy and build the Task Time Tracker application UI following MVC pattern.
  • Demonstrated how to use SenchaCmd to make the application production ready.


Overall I find it as a wonderful book to have if you are developing web applications using Spring/ExtJS. I would give 5 out of 5 star rating for this book.

How to POST and GET JSON between EXTJS and SpringMVC3

After one month of evaluation of the frameworks and tools, i choose ExtJS for UI and Spring/SpringMVC for business layer for my pet project.

Again by using ExtJS we can send data to server by form submits or as request parameters or in json format through Ajax requests. ExtJS uses JSON format in many situations to hold data. So I thought using JSON as data exchange format between EXTJS and Spring will be consistent.

The following code snippets explains how we can use ExtJS and SpringMVC3 to exchange data in JSON format.

1. Register MappingJacksonHttpMessageConverter in dispatcher-servlet.xml

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
</list>
</property>
</bean>

Don’t forget to copy jackson-json jar(s) to WEB-INF/lib

2. Trigger the POST request from ExtJS script as follows:

Ext.Ajax.request({
url : 'doSomething.htm',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
params : { "test" : "testParam" },
jsonData: {
"username" : "admin",
"emailId" : "admin@sivalabs.com"
},
success: function (response) {
var jsonResp = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert("Info","UserName from Server : "+jsonResp.username);
},
failure: function (response) {
var jsonResp = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert("Error",jsonResp.error);
}
});

3. Write a Spring Controller to handle the “/doSomething.htm” reguest.

@Controller
public class DataController
{
@RequestMapping(value = "/doSomething", method = RequestMethod.POST)
@ResponseBody
public User handle(@RequestBody User user) throws IOException
{
System.out.println("Username From Client : "+user.getUsername());
System.out.println("EmailId from Client : "+user.getEmailId());
user.setUsername("SivaPrasadReddy");
user.setEmailId("siva@sivalabs.com");
return user;
}
}

Any other better approaches?