Single Page Applications

Most of today's web applications are written in JavaScript. Java is relegated to the backend and has the important role of dealing with data and business rules. However, much of the GUI stuff is now happening on the client side.

There is a good reason for that in terms of responsiveness and user experience, but those applications add extra complexity.

Developers now have to be fluent in both Java and JavaScript and the number of frameworks can be a little overwhelming at first.

The players

If you want to dig deeper into JavaScript, I would highly recommend Dave Syer's tutorial with Spring and AngularJS, which is available at https://spring.io/guides/tutorials/spring-security-and-angular-js.

Choosing a JavaScript MVC framework can be a little difficult too. AngularJS has had the favor of the Java community for years but people seem to be moving away from it. For more information, visit https://gist.github.com/tdd/5ba48ba5a2a179f2d0fa.

Other alternatives include the following:

  • BackboneJS: This is a really simple MVC framework that sits on top of Underscore and jQuery.
  • Ember: This is a comprehensive system that provides more facilities for interacting with data and more.
  • React: This is the newest project from Facebook. It has a new and very interesting philosophy for dealing with views. Its learning curve is quite steep, but it is a very interesting system to look at in terms of designing a GUI framework.

React is my favorite project right now. It lets you focus on the view and its one-way data flow makes it easy to reason with the state of your application. However, it is still in version 0.13. This makes it both very interesting, as the vibrant community always comes up with new solutions and ideas, and somewhat disturbing, as the road ahead stills seems long even after more than 2 years of open source development. Visit https://facebook.github.io/react/blog/2014/03/28/the-road-to-1.0.html for information on "The Road to 1.0".

The future

I see a lot of Java developers ranting about the permissiveness of JavaScript and having a hard time dealing with the fact that it is not a strongly typed language.

There are other alternatives, such as Typescript (http://www.typescriptlang.org/), which are really interesting and provide the things that we, Java developers, have always used to make our lives simpler: interfaces, classes, helpful support in IDE, and autocompletion.

A lot of people place bets on the next version (2.0) of Angular that will quite notoriously break everything. I think it's for the best. Their collaboration with Microsoft's team that makes Typescript is really unique.

Most JEE developers will smile when they hear that one of the big new features of ECMAScript, that allows the development of this new framework, is decorators, some kind of annotation mechanism:

Note

To learn about the difference between annotation and decorators, visit http://blog.thoughtram.io/angular/2015/05/03/the-difference-between-annotations-and-decorators.html.

JavaScript is evolving quickly and ECMAScript 6 has a lot of interesting features that makes it a really advanced and sophisticated language. Don't miss the boat; take a look at https://github.com/lukehoban/es6features before it's too late!

The web component specification is also a game changer. The goal is to provide reusable UI components, and both the React team and the Angular 2 teams have plans to interface with it. Google has developed an interesting project on top of web components called Polymer that is now in version 1.0.

Note

Refer to the article at http://ng-learn.org/2014/12/Polymer/ to learn more about the state of these projects.

Going stateless

When dealing with a JavaScript client, relying on session cookies isn't the best option. Most applications choose to go completely stateless and identify clients with a token.

If you want to stick with Spring Session, take a look at the HeaderHttpSessionStrategy class. It has an implementation that sends and retrieves sessions with an HTTP header. An example of this can be found at https://drissamri.be/blog/2015/05/21/spr.

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

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