Struts/JSF1/JSF2
Struts structures the components of a Java-based Web application into a unified whole
based on a robust MVC (Model View Controller) design pattern:
- Model represents the data in a database.
- View represents page presentation code,
- Controller represents the navigational code,
Its "separation of concerns" modularization makes it particularly useful so that a large team
of web designers, system analysts, system engineers, database engineers can work in parallel.
The "View" portion of this architecture has undergone very rapid series of improvements,
from "Model 1" to "Model 2" to the component model
of JSF (Java Server Faces), which many are adopting today instead of Struts.
The race is to enable thin browser clients to be as highly interactive as fat Java client apps built using Swing.
Struts is called "action based" because,
being built on Sun's servlet API,
a Struts form is intercepted in the server by a single instance (the "master" ActionServlet)
that delegates actual work to subclasses of ActionForm and Action.
Craig McClanahan at Sun created Struts as part of a project to internationalize an application.
Struts also hasten development of Web applications' user input validation, error handling, reporting, and flow control.
ActionServlet helper classes automatically take care of behind-the-scenes activities
such as initializing Struts extensions (plug-ins), reading configuration data, and pooling Action subclasses (for efficiency).
Craig went on to lead the development of Sun's JSF (Java Server Faces) spec first published in 2004.
This first version of JSF introduced stateful and event-driven architecture versus Struts' stateless action architecture.
JSF 1.2 is a part of J2EE 5.
Servletz
-
Java Servlets were
defined by Sun as programs written in Java that reside on a Web server and respond to user requests
(much like CGI programs used to do).
Servlet containers provided by software such as BEA or Tomcat
take care of parsing HTTP requests, managing sessions, and compiling JavaServer Pages (JSPs).
- JavaServer Pages (JSPs) generate Web pages with both static and dynamic content.
- JavaBeans Components that follow specific rules, such as naming conventions.
- Business logic code that implements the functionality or rules of specific applications,
done by a custom subclass of class org.apache.struts.action.Action.
Apache Struts
JSF
Struts builds on the JSP Standard Tag Library Expression Language (JSTL EL).
Tracing what happens internally:
- The "calculator.jsp" URL (at a web host) typed into a client internet browser arrives at a web server (through DNS).
- The FacesServlet controller web server listener recongizes the jsp and restores the view from the component tree retrieved.
Apply request values; process events
Process validations; process events
Update model values; process events
Invoke application; process events
Render response
- The "calculator.jsp" form contains markup:
<f:view>
<h:form id="calcForm">
<h:panelGrid columns="3">
<h:outputText for="firstNumber" value="First Number" />
<h:inputText id="firstNumber" value="#{CalcBean.firstNumber}" required="true" />
<h:message for="firstNumber" />
</h:panelGrid>
</h:form>
</f:view>
The <f:view> announces a container managed by JSF.
The <h:form> tells JSF to provide a form there.
The <h:panelGrid> tells JSF to provide put a 3-column table in that form.
The <h:inputText tells JSF to provide an input text entry box in that form, with a value from "calcBean".
These <f: and <h: tags are prefixes to the tag library, defined at the top of the "calculator.jsp" file:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
Unlike a specification of where javascript libraries are located,
these are not URLs to actual web pages at Sun.com, but ???
The index.jsp page.
the web.xml and faces-config.xml file, found under the example application's src/webapp/WEB-INF directory.
the Faces Servlet, and Faces Servlet mapping in the web.xml file.
the faces-config.xml file in the web.xml file.
what beans get managed by JSF in the faces-config.xml file.
navigation rules in the faces-config.xml file.
View the model object Calculator.
the CalculatorController to talk to the Calculator model.
The JSF v1 (Model 1 architecture) supported static include tags such as <jsp:useBean>.
Unlike the XML in Struts' tag library, JSF tag library (JTLB) is event-driven, much like
the architecture of Apple's WebObjects and Microsoft's ASP.net.
Under JSF 2.0 that Sun open sourced under their CDDL license,
.tag files in the WEB-INF/tags folder
which provides compile-time checking for required parameters as they are compiled into tag handlers.
Model backing beans map between view and model.
JSF is the base for $799/year commercial tool
Exadel's Visual (web) Component Platform Eclipsed-based Exadel Studio to enable developers to add AJAX
capabilities without writing Javascript code. Its pre-built, customizable plugable RichFaces code
defines user interfaces through one of 14 "skins" that define
themed UI schemes (colors, fonts, corner sharpness, and 3D effects).
Enhancements to the JSF-RI (Reference Implementation)
components to build UI include
MyFaces Tomahawk Extensions
To avoid full page refreshes,
Ajax4JSF is used to render and replace individual components in the
single screen that JSF manages as a tree of components.
Facelets JSF-oriented view technology is used to build a screen.
MyFaces, at 1.1.3 with Shale, is dependent on the
cactus 13-1.7.1 jar,
junit 3.8.1 jar, and
org.apache.struts.shale 1.0.2 jar test framework.
Resources:
JSF for nonbelievers: Clearing the FUD about JSF by Richard Hightower, CTO of ArcMind
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html#wp89664
http://www.oracle.com/technology/pub/articles/cioroianu_tagfiles.html
http://www.onjava.com/pub/a/onjava/excerpt/jserverpages3_ch11/
Ted Husted
The JSF Central website
The JSF FAQ website
|