|
Delve Into Web Tier Components
Use standard JSP actions to build encapsulated and reusable JSP and JSF components.
by Paul Philion
JavaOne, June 29, 2004
In my article, "Take a Tour of Web Tier Technologies," I outline J2EE Web tier technologies and discuss how you can use them to build robust Web applications. Those J2EE Web tier technologies are the subject of many JavaOne sessions this week, so in this article, I'll drill down further into the specific Web tier components.
Software components are essential elements of object-oriented software development. Many of the J2EE technologies are component-based frameworks that provide resources to the components they contain. For example, an Enterprise JavaBean (EJB) is a well-defined component that provides some enterprise-level functions. The container model is called that because it contains components.
Components are not limited to back-end processing. In many cases, developers associate components with objects that present a visual interface to users and encapsulate the objects' behavior. I refer to those specific types of components as user interface (UI) components. Examples of UI components are the UI controls in Swing; buttons; fields; combo boxes; and more.
Regardless of whether a component is a UI component or a nonvisual component, there are several essential component characteristics:
-
Well-defined: A component must have a simple, well-defined, documented interface. Without documentation, a component is useless.
-
Encapsulated: A component must be able to do its work without exposing its inner workings. This allows you to independently change both the component and the applications that rely on it.
-
Reusable: A component should be useful outside the context of a specific application. You don't need the overhead of a component if you can't benefit from its reusability.
-
Composable: Components can comprise more complex components. For example, a dialog component might consist of an image component, a text component, and a button component, all working together.
Together, these characteristics define a piece of software that achieves much with little effort: You can easily add components to an application, and they perform complex operations without exposing the complexity.
JSP Components
The easiest way to use components in JavaServer Pages (JSP) is to implement the component itself as a JSP file. You can include a JSP (or HTML or XML) fragment using the <%@ include %> directive or the <jsp:include> (or <c:import>) standard action. These tags allow you to break down a JSP page into sub-components, and you can use those components in many pages to provide the behavior and look and feel across an entire site.
You can use the <%@ include page="header.jsp" %> directive to include static content in a JSP page. The full content of the included JSP file is copied into the containing JSP page at translation time. This is the most efficient way to include JSP content, but changes to the included file will not be reflected in the containing JSP page, unless it is changed. Further, parameters cannot be passed to a JSP file included this way, so the behavior is limited.
Back to top
|