Saturday, January 28, 2012

Spring MVC 3.1, jqGrid, and Spring Data JPA Integration Guide (Part 3)


In the previous section, we have created the Java classes and discussed jqGrid's jsonReader format. In this section, we will focus on the presentation layer, in particular the HTML and JavaScript files.

Presentation Layer

To display our data without page-refresh and interactively, we will add AJAX and jqGrid, a jQuery plugin, to present tabular data.

What is jQuery?

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.


What is jqGrid?

jqGrid is an Ajax-enabled JavaScript control that provides solutions for representing and manipulating tabular data on the web. Since the grid is a client-side solution loading data dynamically through Ajax callbacks, it can be integrated with any server-side technology, including PHP, ASP, Java Servlets, JSP, ColdFusion, and Perl.



We only have a single HTML file (users.jsp, a JSP to be exact) to perform all actions. This page contains our jqGrid table and buttons for interacting with the data.

Entry page


At first glance, when you look at the JavaScript code, it is somewhat intimidating, but once you've familiarized with the jqGrid syntax, you'll find that it's actually simple. If you aren't familiary with jqGrid, please visit the jqGrid Official Wiki

You might be asking: "What's that humongous lines of jibberish code?" If you'd been following my blog, you would notice that I have tackled jqGrid a couple of times from my previous tutorials. If my explanation in this tutorial isn't enough, please see the following tutorials for an alternative perspective:

An In-depth Look

If we partition this HTML page, you will notice the following sections:
  • URL imports
  • JavaScript and CSS imports
  • jqGrid initialization
  • JavaScript functions: addRow(), editRow(), deleteRow()
  • HTML table

Notice how we've separated the HTML markup from the JavaScript code. We could, of course, move that one huge JavaScript code in an external js file, and make the HTML look somewhat smaller. But I'll leave that exercise to my readers.


In the next section, we will focus on the configuration files for enabling Spring MVC. Click here to proceed.
StumpleUpon DiggIt! Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Spring MVC 3.1, jqGrid, and Spring Data JPA Integration Guide (Part 3) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share


  1. Thank you very much - it was helpful for me :-)

  2. Dear Krams

    I have deployed this project on cloudfoundry , but when I access the url it does not show the jqgid on the page instead show the plain json with i.e

    So please help
    Thank you

  3. Have you tried deploying this on your local machine first? Did you get the same results?

  4. Dear Krams

    Yes , I have tried on localhost , it works fine , no problem , problem in deploying the project on the remote server

    So please help
    Lot of thanks

  5. krams: have you run into the bug with delete?

    It looks like there could be an issue with an improper JS call to the "split" function on an array.

    Error message when using form editing to do a delete is:

    "Uncaught TypeError: Object 1 has no method 'split'"

    Ever run into this?

  6. @Anonymous, I have not encountered that so far. What version of jQuery and jqGrid are you using?

  7. jqGrid 4.3.1 and jQuery 1.7.1.

    It's still entirely possible (nay, likely) I'm doing something stupid, but I found it interesting to see other similar findings in the comments on the above link.

  8. Krams, nice tutorial and I got it to run on my local machine under eclipse easily. However, I when I copied your jqgrid directories (js and css) to a new project, eclipse showed syntax errors in the jquery-1.6.4.min.js file - which it is not doing in your project! How did you set your project that this is not happening? Also, I notice this doesn't happen with your older jqgrid tutorial. Apparently the eclipse parser is out of date, but that doesn't explain why this project doesn't show errors.


  9. I have read your blog its very attractive and impressive. I like it your blog.

    Spring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training

    spring training in chennai spring hibernate training in chennai

  10. BlueHost is the best hosting company with plans for all of your hosting needs.

  11. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    core java training in Electronic City

    Hibernate Training in electronic city

    spring training in electronic city

    java j2ee training in electronic city