Case Study: strategies to do data binding and value building in the application tier

(by Mark Qian on 10/31/2006)

Introduction

One of the major tasks for the application tier in a wab application is the serialize and deserialize data between browsers (a plain-text format, the html document) and the target data beans in the appilcation tier (an object-oriented format), the translation between paremeters in HttpRequests and data beans that you use to invoke API in next tier. When doing the translation, people have been struggling amoung performance, maintainability and flexibility. The goal of this study is to find the suitable way to satisfy most of the struggling issues

In this article, I will first show you several approaches people have been doing and then bring up my solution. Since the situation is similar in vareity of web application frameworks such as Struts, JSF, Spring MVC and so on, I will use Spring MVC as my environment.

I will assume that we have a relatively "complicate" case where a single page contains content from two different data beans at the business tier, in our case, Bamboo and Source. (We will see the live page below in details) You will see a "Bamboo Administration" page when clicking at links "See the page with live code here" below. In the page, there are two subframes, list and edit. In the lower subframe, the edit area, you can modify the info about each selected (from the upper subframe) bamboo and select its whole sale source. What we are talking about for this study is the Save action. When users click at Save button, we submit content from two business data beans, Bamboo and Source.

Note: there are some other issues you may want to take a look on the pageShow details



The Problem:

We have two objects (Bamboo and Source) in the edit page but HTTPRequest flats them into key-value pairs. How do we "translate" those parameters into business objects Bamboo and Source after we receive the requset? The approaches appear as two extrame cases:

The Solution:

So, is there any better solution? Yes .

Note: "better" here means that it should have 1). no hard-coded section at all (in other words, no change should be made for value building/loading in application tier when thins are changed in the business tier.), 2). no wastful "ActionForms", 3). completely isolate presentation from business.





Related Source Codes