|
Article Excerpt When developing Web applications that use Java and XML there are many options, including (among others) the Apache Struts framework and the Extensible Stylesheet Language Transformation (XSLT) language.
At first blush, these options may seem like an "either/or" proposition, considering the fact that the view portion of Struts serves essentially the same purpose as XSLT: to render the view, or visual output, of the application. This article will show how XSLT can be used within the view layer of Struts to leverage the strengths of both and allow you maximum flexibility in the visual presentation of your Java Web applications.
Some of you may be thinking design patterns at this point. That is, Struts uses the model 2 (M2) design pattern, which began as the model-view-controller pattern (see Design Patterns: Elements of Reusable Object-Oriented Software from Addison Wesley). The M2 pattern has been extended by incorporating XSLT (for XML applications), creating the model 2X (M2X) pattern, which is very close to what I'm about to show you. However, I've taken yet another deviation, which I believe adds a greater level of flexibility and robustness.
For the sake of brevity I'm assuming at least introductory knowledge of both XSLT and Struts. I'm also assuming some basic knowledge of the Cascading Stylesheet (CSS) language, because what good would a flexible view layer be without an externalized look-and-feel? I will provide a brief overview of both Struts and XSLT, but those overviews will be neither extensive nor adequate to fully understand the contents of this article.
Overview
One of Stephen R. Covey's Seven Habits of Highly Effective People (Simon & Schuster, 1990) is to "begin with the end in mind." In keeping with Mr. Covey's habit, allow me to show you what we're trying to accomplish. After I show you the end, I'll put everything together piece by piece, to (hopefully) solidify these concepts.
Figure 1 shows each part of the application, highlighting the Struts and XSLT parts.
[FIGURE 1 OMITTED]
Taking a step back from Figure 1, Figure 2 shows which parts of Figure 1 belong to model, view, and controller, respectively.
[FIGURE 2 OMITTED]
What I've added to Struts is a generic view bean, which uses XSLT to transform XML into the view output (e.g., XHTML). For any given view to be rendered, any XML and any XSL stylesheet can be used together to generate the output. The rationale behind this usage, with Web pages in particular, comes from the observation that many (if not most) display (as opposed to input) Web pages are similar in nature.
Generally speaking, Web applications have a kind of template for visually appealing aspects such as a navigation and/or status bar (with and/or without graphics). Within this template, there are usually one or more sections that contain important data; that is, business data within HTML. Take Figure 3, for example.
[FIGURE 3 OMITTED]
The banner and navigation portions of Figure 3, along with the look-and-feel defined by the colors and fonts, make up the template I mentioned earlier. Within this template, there is a listing of persons, ordered by last name. This listing constitutes the dynamic, or business, data, which (in this case) is represented within an XHTML table.
If using Struts alone, this same output could be generated, there's...
|
|

More articles from XML Journal
Leveraging value of disparate information assets: XML to the rescue. (..., April 01, 2003 XMLBeans: the best of both worlds. (First Look)., April 01, 2003 XML Edge 2003 East International XML Conference & Expo: Hynes Conventi..., April 01, 2003 Versatile multimodal solutions: the anatomy of user interaction. (XHTM..., April 01, 2003 Modularize formatting objects: learn how to create flexible, reusable ..., April 01, 2003
Looking for additional articles?
Search our database of over 3 million articles.
Looking for more in-depth information on this industry?
Search our complete database of Industry & Market reports by text, subject, publication
name or publication date.
About Goliath
Whether you're looking for sales prospects, competitive information, company
analysis or best practices in managing your organization,
Goliath can help you meet your business needs.
Our extensive business information databases empower business
professionals with both the breadth and depth of credible,
authoritative information they need to support their business
goals. Whether it be strategic planning, sales prospecting,
company research or defining management best practices -
Goliath is your leading source for accurate information.
|
|