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.

  • Pingback: Backbone.js Wine Cellar Tutorial — Part 2: CRUD()

  • Pingback: Backbone.js Wine Cellar Tutorial — Part 1: Getting Started()

  • Pingback: RESTful services with jQuery and Java using JAX-RS and Jersey()

  • Chandi

    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.

  • Pingback: Backbone.js Wine Cellar Tutorial — Part 3: Deep Linking and Application States()

  • s

    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

  • Pingback: Backbone.js酒窖教程 – 第1部分:入门 | Adobe CS6()

  • Pingback: Backbone.js酒窖教程 – 第2部分:CRUD操作 | Adobe CS6()

  • 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?

  • ashwin74268

    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.

    • Great article, and blog, alas… tried using it, it returns blank page and FF fire bug reports exception ‘a.replace is not a function

      • I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers…..

        • This is really a amazing post. I couldn’t have asked for a much better post than this. I am literally very pleased with this and I just hope that I will keep on getting such amazing posts!

      • I love your own publish. It’s great to determine a person explain in words in the center as well as clearness about this essential topic could be very easily noticed. more information look at website

    • A very awesome blog post. We are really grateful for your blog post.

    • I definitely have to update the assembly version in the config files now. Thanks for this..

  • RD

    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

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

      • blood

        Cold in the northern part of the world have the abilty to freeze your blood instantly

    • Gayatri

      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..

    • Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well

  • poonam

    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

      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;
      }
      }

      • Great post, I have been talking with my friend about, .I would come back to you. Thanks for sharing. Thank you for your blog, very interesting, it’s very informative and useful article. And I guess that they having fun to read this post.

      • Thanks for share this blog it’s very helpful for me and, Welcome to the home of Sexy escorts in all over India, we have very excellent call girls, independent escorts in Ahmedabada.

    • It’s amazing to go to see this post and reading the views of all colleagues on the topic of this article, while I am also zealous of getting know-how.

      • I wish more authors of this type of content would take the time you did to research and write so well. I am very impressed with your vision and insight.

        • Very interesting blog. Alot of blogs I see these days don’t really provide anything that I’m interested in, but I’m most definately interested in this one. Just thought that I would post and let you know.

          • I was reading your article and wondered if you had considered creating an ebook on this subject. Your writing would sell it fast.

          • I definitely agree with what you are saying. I have been talking about this subject a lot lately with my brother so hopefully this will get him to see my point of view. Fingers crossed!

      • Very interesting blog. Alot of blogs I see these days don’t really provide anything that I’m interested in, but I’m most definately interested in this one. Just thought that I would post and let you know.

      • So happy to find good place to many here in the post, the writing is just great, thanks for the post.

    • These are usually the basic suggestions for successfully effectively successfully secured up delicate as well as problems together with excellent protection and also easiness.

      • i love alternative treatments because it is simple and does not have nasty side effects*

      • There’s a lot of folks that I think would really appreciate your content.
        Please let me know.

      • This is exactly what I needed when I moved to Dallas about a year and a half ago! I can’t wait to share this insight with newbies who I know that will be moving to the area!

    • I thinke that we neen to do more reseach on this polycystic my faimly has it and the kids my husban had it to there as to be a way that we can come up with somthing…

    • nice blog like this please visit there…

    • This is really a amazing post. I couldn’t have asked for a much better post than this. I am literally very pleased with this and I just hope that I will keep on getting such amazing posts!

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

    • This is exactly what I needed when I moved to Dallas about a year and a half ago! I can’t wait to share this insight with newbies who I know that will be moving to the area!

    • I can give you the address Here you will learn how to do it correctly. Read and write something good

    • link

      Excellent stuff from you, mate. This is some great writing from your side. Without any doubt, this is the greatest article that you’ve submitted on this blog. how to get gmod for free

  • rkoma

    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…

    • It seems like many people are exploring the community for some offers. That’s a good try because the chance is so open in here.

  • APC

    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.

    • Thanks a lot for sharing this with all people you actually understand what you are speaking approximately!

  • 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.

    • Your posts are very interesting and very nice to read and write and gain more knowledge for students they needs to develop…

  • It was better to use JPA instead!

  • 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.

    • This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject.

  • 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.

  • 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.

    • Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work

  • Gayatri

    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???

  • i will use js ..

  • 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.. This is confusing me, Java tech not my style.. Thanks for support please.

  • ali khan

    Google search engine and there are a lot of organizations out there in Internet area which declare to be able to get your web page more extremely rated later on. property valuation sydney

  • FGJD FDJH

    If you are items or services based mostly company then you definitely must notify regarding the item, its costs and so on. polkadot.it

  • Danielgrant

    Therefore, more variety of individuals is taking up the career, which in turn is improving the employment rate, and improving the quality of life of the individuals. link m88

  • 1

  • sree

    Hi Christophe,

    I am new to backbone and i have followed this tutorial and tried this application using Oracle as back end. Server response data is stored under following line

    this.model.models.attributes.wine // http://localhost:8080/app/wines

    instead of saving into following line

    this.model.models.
    i am mapping wines list data to this.model.models manually. please correct me to whats i am doing wrong here to get wines list json data into this.model.models.

  • quality, reliable, cost-effectiveness and the associated jobs are done imalattan.profesyonel team

  • our blog content for the like phase! I am aware of this approach service plan which usually really helped others come up with all the truly! I mean, as to why might we have to suffer through wishing to come up with individuals Wilderness Adventure

  • google

    Therefore, more variety of people is taking up the career, which in turn is helping the use rate, and helping the total well being of the individuals.
    Continue

  • Good Web page absolutely, you will discover some sort of several approaches right after visiting kinds submit.

  • I desired to thank you for this exceptional read Thanks.

  • go to my blog

    An important focus for SEO companies is to provide their clients with websites with some top top high quality information such as blogs and useful pages. go to my blog

  • go to my blog

    I’m satisfied I situated this blog! Every now and then, learners want to perceptive the important factors of efficient imaginary content composing. see post

  • I was about to say something on this topic. But now i can see that everything on this topic is very amazing and mind blowing, so i have nothing to say here.

  • Therefore, more variety of individuals is taking up the career, which in turn is improving the employment rate, and improving the quality of life of the individuals.

  • I think this is a real great blog post.Really looking forward to read more. Keep writing.

  • I just found this blog and find the information on the ssae 16 audit very helpful. Keep up the great work, its hard to find good ones. I have added to my favorites

  • Thanks for such an excellent post. It is such a pleasure to look forward to your blog.

  • This is really a fascinating blog, lots of stuff that I can Get into. One thing I just want to say is that your Blog is so perfect

  • Howdy! I could have sworn I’ve visited this blog before but after browsing through some of the posts I realized it’s new to me.

  • ak123

    This is really awesome post thanks for sharing this. canadians living in
    Texas

  • ak123

    I just found this blog and find the information on the ssae 16 audit very helpful. Keep up the great work, its hard to find good ones. Thanks
    certified financial
    planner san jose

css.php