Section 15.6. JSP Satellite Developments

   

15.6 JSP Satellite Developments

By early 2003, JSP 1.3 should be released. A number of features will be added to this release. In the meantime, there are a number of important developments in the world of JSP that can help developers get the job done, working in conjunction with JSP. In the following sections, we will introduce these so that you have enough information to look into them yourself.

15.6.1 Struts

Struts, began by developer Craig McClanahan, is the name of an open-source product by the Jakarta project at Apache. Struts is a very large application framework that defines numerous custom tags. Its purpose is to provide an open -source framework for working with servlets and JSPs.

Struts is based on the Model-View-Controller design pattern, discussed in the previous chapter. Model components (the data objects) are not included with Struts. These must be defined as custom business logic by the developer implementing the Struts framework. View components include many JSP tags that mimic and extend the behavior of regular HTML tags. Here is an example of a Struts view tag at work:

 <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>  <html:form action="userLoginAction.do" name="loginForm"           type = "javafocf.LoginForm>    Username: <html:text property="username"><br/>    Password: <html:password property="password"></br> <html:submit/> </html:form> 

The custom <html> JSP tags in this snippet look familiar. They are very much like their true HTML counterparts, with an important difference: They have a property attribute. This names a unique attribute present in the ActionForm bean defined for this form. The object created by the LoginForm will have the properties referenced set to the field values.

The Controller component included with Struts is its central, pivotal member. A servlet called ActionServlet takes requests from the client and forwards control of the request to a user -defined Action class. It is mapped to a set of URLs in the web.xml file; often the mapping is to .do , as in the above example. There is a servlet configuration process that uses a number of initialization parameters in a file that is generally called struts-config.xml . This file defines how the application will respond to and route requests. Such mappings are defined as ActionMappings ; objects of this class map a given Action subclass to a given request.

You write Controller components to do the work of your application by writing classes that extend org.apache.struts.action.Action class. The actual work of your component you write inside the perform() method, which looks like this:

 public ActionForward perform(ActionMapping mapping,       ActionForm form,      HttpServletRequest req,      HttpServletResponse, res)               throws IOException, ServletException 

An ActionForward object names the view component to which the request should be forwarded once processing is complete. ActionForward objects map JSPs to logical names in the struts-config.xml file.

An ActionForm subclass is a JavaBean that provides structured access to the request parameters coming in from the form, and can store them as session or request values and perform validation, forwarding the view back to the form page for correction if necessary. Struts also defines error message classes for this purpose ( ActionError and ActionErrors ).

Struts was developed beginning in May of 2000, so it predates the JSTL. That means that there is a bit of overlap in their functionality, particularly with the formatting tags.

Note

If you are interested in Struts, its homepage is at http://jakarta.apache.org/struts/. You can download the framework and find out more about it here.


15.6.2 JavaServer Faces

JavaServer Faces offers a way for developers to work with a standard framework for creating GUI components. The design goals of JSF as defined in JSR 127 read as follows :

  1. Create a standard GUI component framework that can be leveraged by development tools to make it easier for tool users to both create high-quality GUIs and manage the GUIs' connections to application behavior.

  2. Define a set of simple lightweight Java base classes for GUI components, component state, and input events. These classes will address GUI lifecycle issues, notably managing a component's persistent state for the lifetime of its page.

  3. Provide a set of common GUI components, including the standard HTML form input elements. These components will be derived from the simple set of base classes (outlined in #1) that can be used to define new components.

  4. Provide a JavaBeans model for dispatching events from client-side GUI controls to server-side application behavior.

  5. Define APIs for input validation, including support for client-side validation.

  6. Specify a model for internationalization and localization of the GUI.

  7. Automatic generation of appropriate output for the target client, taking into account all available client configuration data, such as browser version, etc.

  8. Automatic generation of output containing required hooks for supporting accessibility.

Note

As mentioned in the previous chapter, new Java technologies are put forward with Java Specification Request documents created by the Java Community Process. JavaServer Faces is JSR 127, and you can investigate its homepage here at www.jcp.org/jsr/detail/127.jsp.


As you can see, there is some overlap with Struts; this is generally viewed as a strength, however, as the two may likely converge the best of both worlds .

15.6.3 Cocoon

Cocoon, sponsored by Apache, began in 1999 as a project of Stefano Mazzocchi. It is at heart a dynamic content generation tool, kind of the way JSP and Cold-Fusion are. Cocoon is entirely XML-based, however. Every request passed through Cocoon statically or dynamically produces XML, and then transforms it and formats it for the response. Cocoon makes it fun to generate output suited for all different kinds of devices, including HTML, WML, PostScript, or SVG.

Cocoon is essentially a servlet that receives requests. It generates a stream of XML events to be fed through a pipeline and uses the SAX events model to process the source. Finally, a serializer creates output from the processing in the form of HTML, WML, text, XML, SVG, etc. Commonly an XSLT transformer is wedged in here, running an XSL stylesheet against the source document to transform the display.

You can find out more about Cocoon at http://xml.apache.org/cocoon.

15.6.4 Log4J

This is another open-source project sponsored by Apache Software Foundation. It was founded by Ceki Gulcu, whose vision was to offer a simple but powerful way for Java developers to integrate logging into their applications. To follow the latest developments of Log4J, visit http://jakarta.apache.org/log4j.


   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net