ATG Programming Guide

Separating JSP Code and Java Code

The previous sections showed how you can write ATG servlet beans that generate JSP code from Java code, while still being able to display parameters defined in a JSP and setting parameters for those displayed parameters.

These functions give you the ability to write applications that completely separate JSP formatting from Java functionality, which is one of the main goals of tag libraries. This separation is essential in large applications because it allows JSP designers and Java coders to work together and maintain autonomy.

As an example, consider the following ATG servlet bean that displays a list of numbers. Name this servlet bean Counter.java and create a class and component for it as described in Simple ATG Servlet Bean Example:

At first, this looks like a simple and workable solution. The problem is that the ATG servlet bean now contains formatting information. This formatting information is usually subject to change many times during the course of development. If every change requires a designer to ask a Java developer to change and recompile a Java class, the simple solution becomes an obstacle.

When you use ATG servlet beans, you can rewrite the previous example so that all of the JSP is removed from the Java object, while the functionality is retained by the Java object:

This new ATG servlet bean has no formatting left in it at all. Instead, the ATG servlet bean relies on the formatting to be passed as a parameter called lineformat. It then uses the number parameter to set the value for each line. The ATG servlet bean is then invoked from a JavaServer Page like this: