Using Backbone.js with a RESTful Java Back-End

In a previous post, RESTful services with jQuery and Java using JAX-RS and Jersey, I demonstrated how to build a RESTful API using JAX-RS and Jersey, and how to build a jQuery application that leverages that API. The application used as an example was a Wine Cellar management application.

In follow-up posts, “Backbone.js Wine Cellar Tutorial” (part1, part 2, part 3), I showed how to add structure to the client-side of the Wine Cellar application using Backbone.js. But that three-part tutorial was provided with a PHP back-end.

By popular demand, here is a version of the Backbone.js Wine Cellar application powered by a Java / JAX-RS back-end using Jersey. The server-side of the application provides an example of building a complete RESTful API in Java using the different HTTP methods:

  • GET to retrieve and search wines
  • POST to add a wine
  • PUT to update a wine
  • DELETE to delete a wine

As already mentioned, the client-side of the application provides an example of adding structure to your JavaScript code using the Backbone.js Model, View and Router components. To learn more about the Backbone.js implementation, refer to the three part tutorial mentioned above: it is entirely back-end agnostic.

The source code for this application is hosted on GitHub here. It consists of the Eclipse Dynamic Web Project with the source code for both the Java back-end and JavaScript/Backbone.js client.

You can run the application (Part 3) here. The create/update/delete features are disabled in this online version.

24 Responses to Using Backbone.js with a RESTful Java Back-End

  1. Chandi January 13, 2012 at 7:18 pm #

    Hi Christophe, I’m an ardent follower of your tutorial apps. Have you considered knockout.js as an alternative to the Backbone.js + Mustache.js combination? The data binding in knockout.js seems very natural to me being a Flex developer. It would be great to see the Wine app refactored to use Knockout.js for comparison.

  2. s May 4, 2012 at 6:32 am #

    Could you please explain, where findById is calling in java application,
    when i changed from one product to other product it is not calling any function, even
    i opened the url (http://localhost:8080/cellar/#wines/1) in other browser and it was making call to findAll().

    Please explain me the purpose of findById.
    Thanks

  3. Personal Loan January 26, 2013 at 7:35 pm #

    Thank you for the good writeup. It in fact was a amusement account it.
    Look advanced to far added agreeable from you! By the way,
    how could we communicate?

  4. ashwin74268 February 12, 2013 at 8:14 pm #

    I am trying to return a JSON response with the same code but keep getting below error:-
    Method : find all Wines in Store
    Feb 12, 2013 3:14:30 PM com.sun.jersey.spi.container.ContainerResponse write
    SEVERE: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/json, was not found
    Feb 12, 2013 3:14:30 PM com.sun.jersey.server.impl.application.WebApplicationImpl onException
    SEVERE: Internal server error
    javax.ws.rs.WebApplicationException.

    I tried everything but it did not worked. Can youplease help me.

  5. RD March 9, 2013 at 8:22 am #

    sir there is problem for running the application after done all the connection , and while running the application it looks only in heading tag as Welcome to Backbone Wine Cellar
    and one empty panel on left side,sir reply me fast the complete procedure for running application

    • poonam July 19, 2013 at 3:15 am #

      Did you get the solution???? Please help me..

    • Gayatri November 1, 2014 at 1:14 pm #

      Hey just check the web browser developer tools for debugging and checking the error in the application. If its coming blank means either you have some problem in your connection string in the sql java code..

  6. poonam July 18, 2013 at 7:12 am #

    Sir,
    There is problem for running the application after done all the connection , and while running the application it looks only in heading tag as Welcome to Backbone Wine Cellar
    and one empty panel on left side. My connection URL is:
    jdbc.url=jdbc:mysql://localhost:3306/cellar?user=root;password=root
    or
    jdbc.url=jdbc:mysql://localhost:3306/cellar?user=root&password=root
    I tried with both but no luck.
    Please help.
    Thanks in advance

    • Obiwan March 17, 2014 at 11:31 am #

      private ConnectionHelper()
      {
      String driver = null;
      try {
      Class.forName(“com.mysql.jdbc.Driver”);
      url = “jdbc:mysql://localhost:3306/mydb”;
      ResourceBundle bundle = ResourceBundle.getBundle(“mydb”);
      driver = bundle.getString(“jdbc.driver”);
      Class.forName(driver);
      url=bundle.getString(“jdbc.url”);
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      public static Connection getConnection() throws SQLException {
      if (instance == null) {
      instance = new ConnectionHelper();
      }
      try {
      return DriverManager.getConnection(instance.url, “root”, “passw”);
      } catch (SQLException e) {
      throw e;
      }
      }

  7. Değişik Tarifler July 25, 2013 at 9:27 am #

    I’m an ardent follower of your tutorial apps, thanks…

  8. rkoma August 27, 2013 at 4:47 pm #

    Hi,

    first of all I must say this is a great tutorial.

    However, I have tried to deploy this app on google app engine and it seems that there is a problem with REST API. Can anyone tell me is this a general problem with cloud storage? I am stuck with this Server error (500) for days…

  9. APC April 19, 2014 at 9:38 pm #

    You will have access to courses that will train you on how
    to use Quick – Books versions 2009 and 2010. Organizations does not have only one aspect accounting, there are many other aspects of an organization and as organization grow in size and business volume
    increases few more aspects come into picture or become very important like SCM, Marketing, Human
    resource, Multiple Inventory, SFA, logistics etc.
    Quite frankly, I don’t think I learned much other than bank recs, which I
    got wrong every month, and setting up a filing system for legal documents, where I color coded file folders and
    grouped them into hanging folders.

  10. http://stephencrowder.weebly.com/ April 21, 2014 at 3:56 am #

    It is near the Glacier National Park that it will be is
    easy for you to visit the park also. Whether your kids are toddlers or teenagers, one Christmas classic is sure to please: The Nutcracker
    Ballet. ” According to Paisley Park Enterprises, the company that oversees most of Prince’s business interests, 3121 is a combination of floral scents and “mysterious” blends that capture the essence of Prince’s eclectic musical style and genius.

  11. Mehrdad April 23, 2014 at 3:07 am #

    It was better to use JPA instead!

  12. www.stephencrowder.weebly.com/ April 23, 2014 at 2:38 pm #

    Most people I knew from high school went to them all the time, but I wasn’t so
    lucky darn it. That’s why Japanese people have called him Prince since then.
    This is a perfect place for families to have
    their vacations as this little island offers a lot of paved and
    gravel roads for the hikers to enjoy.

  13. Rachele April 27, 2014 at 7:23 pm #

    Get a professional septic tank cleaning service
    to clean and empty the tank at affordable cost.
    There are also some requirements to meet, such as enough space and soil.
    This wastes a great deal of water as well as causes a constant influx of water into the septic system.

  14. Garland May 3, 2014 at 2:08 am #

    We have the lowest prices and the largest selection of seating for all Sports, Concerts, and Theater events.
    That’s why Japanese people have called him Prince since then.
    This is a perfect place for families to have their vacations as this little island offers a lot of paved and gravel roads for the hikers
    to enjoy.

  15. Gayatri November 1, 2014 at 1:17 pm #

    hey Cristophe this tutorial and sample applictaion of yours was really helpful for me.

    I have one requirement. How can I integrate this application with my struts application when I tried to integrate it gave url resource mapping error. can you please help me out.

    Is it possible to use SPring or Strurts as backend instead of pure java classes???

Trackbacks/Pingbacks

  1. Backbone.js Wine Cellar Tutorial — Part 2: CRUD - January 11, 2012

    [...] UPDATE (1/11/2012): A version of this application with a Java back-end (using JAX-RS and Jersey) is also available on GitHub here. You can find more information on the Java version of this application here. [...]

  2. Backbone.js Wine Cellar Tutorial — Part 1: Getting Started - January 11, 2012

    [...] UPDATE (1/11/2012): A version of this application with a Java back-end (using JAX-RS and Jersey) is also available on GitHub here. You can find more information on the Java version of this application here. [...]

  3. RESTful services with jQuery and Java using JAX-RS and Jersey - January 11, 2012

    [...] UPDATE (1/11/2012): A version of this application using Backbone.js at the client-side is also available on GitHub here. You can find more information on the Backbone.js of this application here. [...]

  4. Backbone.js Wine Cellar Tutorial — Part 3: Deep Linking and Application States - January 31, 2012

    [...] UPDATE (1/11/2012): A version of this application with a Java back-end (using JAX-RS and Jersey) is also available on GitHub here. You can find more information on the Java version of this application here. [...]

  5. Backbone.js酒窖教程 – 第1部分:入门 | Adobe CS6 - May 24, 2012

    [...] Download a version of this application with a Java back-end (using JAX-RS and Jersey) on GitHub. Read about the Java version of this application in my blog post, Using Backbone.js with a RESTful Java Back-End. [...]

  6. Backbone.js酒窖教程 – 第2部分:CRUD操作 | Adobe CS6 - May 24, 2012

    [...] Download a version of this application with a Java back-end (using JAX-RS and Jersey) on GitHub. Read about the Java version of this application in my blog post, Using Backbone.js with a RESTful Java Back-End. [...]

Leave a Reply

css.php