Git Product home page Git Product logo

jquery-springmvc-jpa's Introduction

Template JPA 2, Spring 3.1, Backbone JS 0.9

This project aims to be the cleanest and most up to date way to build Web UI on a Java-based server.

Of course, this implies lots of framework and architecture choices which are mine and can be discussed.

This repo is in constant evolution but you can find in branches the major architectures switch. At this time, there is one old branche which is jQuery UI that I replaced by BackboneJS (I know that the two technologies are not the same but I still replaced on by the other).

This version is less ambitious than the previous one as there is only read only features, I apologize but have unfortunatly my own planning constraints.

My goal is to fully comment the code and the Git repository to explain how the different technologies are integrated.

Chosen technologies

As described in the main title, the major technologies are JPA 2, Spring 3.1 and Backbone JS 0.9 but this is the complete list of architecture choices:

Java frameworks

JavaScript frameworks

Design patterns and guide lines

Key integrations

This sections contains a quick description of the key integration points between all technologies with a link to the file involved.

No XML Spring configuration

Servlet 3.0 and Spring 3.1 adds support of full Java based configuration replacing web.xml and applicationContext.xml. It allows smaller and compiled configurations for building XML free applications.

This application demonstrate this new way of configuration. As I writing this, Spring Security doesn't implement XML free configuration. Security configuration and Maven configuration are the last XML file of the application.

Spring Data JPA configuration

Repository layer of the application is fully implemented by Spring Data JPA. The configuration is in the file applicationContext.xml with the namespace "jpa". As you can see, only the root package for repository interfaces is needed.

The Spring Data JPA implement standard JpaRepository interface methods and the specifics defined in the interface.

Spring MVC, Spring Data Rest

Spring Data Rest is very good new idea of Spring Source team and build a bridge from Spring Data to Spring MVC. It allows us to automatically published a Spring Data models.

Spring MVC is used to publish a more specialized service which is the ajax login. in very standard way. The DispatcherServlet is declared in the web.xml.

Single page application even for login

The web application respect the concept of Single-page application even for the login phase.

In order to do that, all the web application code (HTML, CSS, JS) is not secured but only the JSON RPC calls are. It's the JavaScript application which starts to check user authentication with the server and open a modal popup if needed.

In the Spring Security side, all is configured in applicationContext.xml, the filtering is triggered only on "/rest/*" with an exception on "/rest/login" to be able to log on. The standard Spring Security's configuration with a automatic form login is also removed and replaced by a simpler "403 Forbidden" handler.

The LoginController.java handles login request mapped with HTTP methods : GET for status, POST for login and DELETE for logout. This class is a little more tricky because there is sadly no standard "Ajax login" implemented in Spring Security and we have to manage Spring Security context.

Finally, there is the login.js module which handle login behaviors in the gui. It handles a globally accessible status variable, start with a checking on login status, open the login dialog and publish a logout function.

RequireJS configuration and structure

The JavaScript application is structured with the Asynchronous Module Definition (AMD) API. It structure the code with modules, handles JavaScript files loading and dependencies.

RequireJS is the implementation used to do this. The application's JavaScript bootstrap start in the index.html with the require.js script and a "data-main" attribute which target the main.js root script. This root script configure RequireJS, define some dependencies and bootstrap the application including the login module.

Backbone JS Web UI structure

The Web UI is structured with Backcbone JS. All concepts of Backbone are used in the project : Model with the login status, Collections with the users and skills, View with all components of the interface : login popup and data grids, and finally Router which drive the Url hashtags listening.

All Backbone objects are defined as RequireJS modules with dependencies on js and text files.

Backbone JS Hateoas models

Hateoas used in Spring Data Rest are structured JSON data which allow to abstract parsing and automatically construct Backbone models and collections to navigate into data.

Data mapping in the project are mostly generic and placed in a special Hateoas Backbone extension which implements this concept.

jquery-springmvc-jpa's People

Contributors

swiip avatar xuyuanme avatar

Watchers

James Cloos avatar Gavin.C avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.