Modeling Web Pages
Web pages, whether scripted or compiled, map one-to-one to components in UML. Components are physical and replaceable parts of the system. The Implementation view of the model, also known as the Component view, describes the components of the system along with their relationships. See Figure 3.14 for a look at the diagramming types used in UML. In a Web application, this view describes all of the Web pages of the system along with their relationships with each other (such as hyperlinks). At one level, the component diagram of a Web system is much like a site map.
Since components represent only the physical packaging of interfaces, they are not suitable for modeling the collaborations inside the pages. This level of abstraction, which is extremely important to the designer and implementer, still needs to be part of the model. We could say that each Web page is a UML class in the model's Design view, also known as the Logical view, and that its relationships/associations to other pages represent hyperlinks. This abstraction tends to break down when you consider that any given Web page can potentially represent a set of functions and collaborations existing only on the server, while a completely different set may exist only on the client. Any server-scripted Web page that employs Dynamic HTML (client-side scripting) as a portion of its output is an example of this type of page.
Figure 3.14 Diagramming UML.
The immediate reaction to this problem might be to stereotype each attribute or operation in the class to indicate whether or not it is valid on the server or client side. It is at this point that our model, originally intended to help simplify things, starts getting quite complicated.
A better approach to the problem is the principle of separation of concerns. The behavior of a Web page on the server is completely different from its behavior on the client. While executing on the server, it has access to and relationships with server-side resources such as middle-tier components, databases, and file systems. That same page, or the streamed HTML output of the page, has a completely different behavior and set of relationships when on the client. On the client, a scripted page has relationships with the browser itself via the Document Object Model (DOM) as well as with any Java applets, ActiveX controls, or plug-ins that the page specifies. For serious designers, there can be additional relationships with other active pages on the client that appear in another HTML frame or browser instance.
Separating concerns, the server-side aspect of a Web page can be modeled with one class, while the client-side aspect is modeled with another. The two are distinguished through use of UML's extension mechanism defining stereotypes and icons for each server page and client page. Stereotypes in UML allow the defining of new semantics for a modeling element.
For Web pages, stereotypes indicate that the class is an abstraction of the logical behavior of a Web page on either the client or the server. The two abstractions are related to each other with a directional relationship between them. This association is stereotyped as «build», since server pages build client pages. In other words, every dynamic Web page whose content is determined at runtime is constructed with a server page. Every client page is built by a single server page at most; however, it's possible for a server page to build multiple client pages.
Hyperlinks are a common relationship between Web pages. Hyperlinks in a Web application represent navigation paths through the system. These relationships are expressed in the model with the «link» stereotyped association. As a rule, this association originates from a client page and points to either a client or server page. See Figure 3.15 for the makeASale relationships that can be diagrammed with the TogetherSoft tool.
Hyperlinks are implemented as a request for a Web page. Those Web pages are modeled as components in the Implementation view. Typically, a link association to a client page is equivalent to a link association to the server page that builds the client page. This is because a link is in reality a request for a page, not either of the class abstractions.
Because a Web page component realizes both page abstractions, a link to any of the classes realized by the page component is equivalent. Tagged values are utilized for defining the parameters that are passed along with a link request. The «link» association tagged value Parameters is a list of parameter names along with optional values that are expected and used by the server page processing the request.
Figure 3.15 Relationships in UML.
These stereotypes make it easier to model a page's scripts and relationships. The «server page» class's operations become functions in the page's server-side scripts; its attributes become page-scoped variables that are globally accessible by the page's functions. The «client page» class's operations and attributes also become functions and variables visible on the client.
The key advantage to separation of the server- and client-side aspects of a page into different classes is in the relationships between pages and other classes of the system. Client pages are modeled with relationships to client-side resources such as DOM, Java applets, ActiveX controls, and plug-ins. Server pages are modeled with relationships to server-side resources such as middle-tier components, database access components, and server operating system.
One of the biggest advantages of using class stereotypes when modeling the logical behaviors of Web pages is that their collaborations with server-side components can be expressed in much the same way as any other server-side collaborations. The «server page» is just another class participating in the business logic of the system. On a more conceptual level, generally server pages take on the role of controllers. They orchestrate the necessary business object activity to accomplish the business goals initiated by the browser's page request. See Figure 3.16 for an activity view of shopping within the SilverBooks sample application.
Figure 3.16 Sample application activity diagram.
On the client side, collaborations tend to be more complicated, partially due to the wide variety of technologies that can be employed. In the simplest form, a client page is an HTML document containing both content and presentation information.
Browsers render HTML pages using formatting instructions in the page or in a separate style sheet. In the logical model, this relationship would be expressed with a dependency from a client page to a «Style Sheet» stereotyped class. Since style sheets are primarily a presentation issue, they are often left out of the Application Design Model (ADM).
The principal mechanism for entering data in Web pages is the form. In an HTML document, forms are defined with <form> tags. Each form specifies the page to which it should submit itself. A form also contains a number of input elements that are expressed as HTML tags. The most common of these tags are <input>, <select>, and <textarea>. The <input> tag can be a text field, check box, radio button, push button, image, hidden field, or one of a few other less common types.
Modeling forms is achieved through the «Form» class stereotype. A «Form» has no operations because any operations that might be defined in a <form> tag are really owned by the client page. The input elements of the form are all stereotyped attributes of the «Form» class. A «Form» can have relationships with applets or ActiveX controls acting as input controls. Each form also has a relationship with a server page, which is the page that processes the form's submission. This relationship is stereotyped as «submit». Since forms are contained entirely in an HTML document, they are expressed in a UML diagram with a strong form of aggregation.
Use of HTML frames in a Web site or application has been a subject of debate since their introduction. Frames allow multiple pages to be simultaneously active and visible to the user. The most common browsers today allow multiple browser instances to be active on the user's machine as well. These pages can interact with each other through use of Dynamic HTML scripts and components. The potential for complex interactions on the client is significant, and the need for modeling this even greater.
The software architect decides whether frames or multiple browser instances are employed in an application. If frames are used, the model of this client-side behavior needs to be represented in the ADM. To model frame usage, define two more class stereotypes, «frameset» and «target», as well as the association stereotype «targeted link». A frameset class representing a container object maps directly to the HTML <frameset> tag. This class contains client pages and targets. A target class is either a named frame or browser instance that is referenced by other client pages. A targeted link association is a hyperlink to another page that is rendered in a specific target. The actual presentation specifics are, for the most part, captured by tagged values in the frameset and the associations. Two tagged values on the aggregation relationship between a frameset and a target, or client page, identify the frameset row and column in which the target, or page, belong. The tagged value Target on the targeted link association specifies the «target» where the page should be rendered.
In cases where a target is not aggregated with a frameset, a separate browser instance is used to render the pages. It should be kept in mind that this notation is expressing a single instance of a client machine. It is assumed that all multiple independent targets are running on the same machine, with the diagram expressing the client-side behavior of one client instance. Any other deployment configuration would need to be heavily documented in the model to be better understood.