Tips, tricks and tools for creating your own data-driven app, brought to you in partnership with Qlik.

In the spirit of my previous article, this one is a quick guide showing how to handle HTML forms with Apache Struts 2, and how a web form is sent within a web application can be delegated to an external entity with a decoupling model. If we skip the validation step which can be done on the client-side with JQuery Form Validator, then let's see choice by choice the skeleton of how to manage the creation and the display of customers.

No Decoupling, No Ajax

This is the traditional model in which a form is displayed in its own page with a redirection to another page once the data is saved to display the list of entities.

Decoupling, Ajax

This is my favorite one and the modern way since we need no Java, no POJO, no Action and CRUD can be automated with JavaScript since we know how to serialize an HTML form and how to communicate with an external entity like Node.js through REST and CORS using the HTTP verbs.

Since its 4.0 version, Express comes with the new Router which is like a mini application to create modular, mountable route handlers and provides us with the routing APIs like use, get, post, put, delete, param and route. The cors module provides an Express/Connect middleware to enable Cross Origin Resource Sharing with various options. The extended option of the bodyparser module which parses incoming request bodies in a middleware before your handlers, allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). The "extended" syntax allows for rich objects and arrays to be encoded into the URL-encoded format with square brackets [], allowing for a JSON-like experience with URL-encoded.