Abandon Struts tags, use HTML and Dojo

Reading some tutorials and articles about DojoToolkit and thinking about a web application with Struts 2 I can say it is the best to separate the presentation layer and middle layer.

The presentation layer is just about the presentation and therefore a combination of HTML, JavaScript and the DojoToolkit are enough libraries to use. When someone then has to also know the Struts Taglibs for Ajax it’s getting dirty. So my advice is to really separate the presentation layer from the middle layer. This also helps if the correct person is creating the user interface. Because this person often knows nothing about Java, JSP or PHP but is very comfortable with browser technologies like HTML and JavaScript. So for him just learning the API of the DojoToolkit is not too much.

The communication between the presentation layer and facade layer can only be done using HTTP. A typical approach is to use XML or JSON to transfer information. The user interface developer can create a GUI prototype before the real underlying layer is ready by using static files as part of the web application for data. Later on the static files are exchanged with the correct remote invocation.

In the middle layer, if you want to call it facade or service layer, the Struts Actions are used to handle the HTTP-Requests from the presentation layer and return the data in a readable format, which may be JSON or XML. This often implies converting the domain model in data chunks for the presentation layer to display. For data chunks the Data Transfer Object pattern is a good candidate because a DTO represents a single chunk of information which is only needed and assoziations are cutted correctly.

This separation really helps keeping the technologies separated and makes it easier to concentrate on the main tasks. The user interface is developed with HTML, JavaScript and Dojo and the middle layer with Java or PHP. I think this is much better than having a mixture of everything together.