Chapter 6. Building a Single-Page Spring Application

Having mastered many powerful features of Spring Framework while handling all the major technical concerns of enterprise applications, it is time to build a modern web application by putting all the techniques we learned in the previous chapters together. The current trend in web development is to build single-page applications (SPAs) that offer native-like user experience and an intuitive UI. In this chapter, let's build a responsive SPA powered by a Spring backend.

We will use Ember.js for building the SPA and Bootstrap for styling and responsive behavior. For Ember development, we will use a command-line tool called Ember CLI, which runs on Node.js and combines a collection of supporting tools for various critical functions of JavaScript-based modern frontend development.

The motivations behind SPAs

We know that Spring mainly focuses on the server side, that is, the integration, service, and data layers. Spring relies on other web technologies for rendering the presentation layer. Although Spring MVC does facilitate the presentation layer with the help of web technologies such as JSP and Thymeleaf, all of them work based on server-side rendering and full-page refreshes for responding to user interactions. In this traditional approach, the presentation layer of a web application is composed of a bunch of totally independent HTML files served by a server on demand, each representing a single screen, with just one rendered to the client browser at a time, taking a full round trip to the server for each user interaction. This provides a very poor user experience compared to native desktop applications, which gracefully re-render just the specific parts of the screen when required.

Although you can use some AJAX-using frameworks such as jQuery, in order to get data from a server or even for partial rendering of the UI (as in the case of JSF), it requires a lot of server resources for the presentation layer, and server processing is easily exhausted when the number of concurrent users grows. The presentation layer concerns are distributed across both the server and client tiers in this approach. UI developers need both client-side as well as server-side skills in this case, which makes web development harder.

Web developers had always been looking for a smarter method to build the UI of a data-driven application which is developed entirely on the client side, running inside a web browser, which offers a native-like rich user experience without a full refresh to the server for page transitions and navigations. They wanted a way to make their UI dynamic with data purely on the client side, eliminating the need for a server during frontend development, and plugs in to the server only when everything is ready on the client side. And for all these problems and requirements, the SPA paradigm is the answer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset