|
Art of Java Web development
Summary In this article, an excerpt from his book Art of Java Development, Neal Ford introduces the WebWork open source development framework. And More...
Go to Web Site
|
|
|
|
You can configure WebWork through configuration files. When WebWork starts, the ServletDispatcher is invoked. This is the main controller for WebWork, similar to other Model 2 frameworks. The ServletDispatcher reads several configuration files (covered in "The Configuration" section below) and uses that information to create an Action object to handle the request. The action in turn creates model beans, which access data, mutate it, and otherwise perform the real work of the application. WebWork does not require the use of model beans. Properties can appear directly in the Action class but shouldn't for most Model 2 applications because such an arrangement violates the separation of responsibilities.
The action returns a response code, used by the ServletDispatcher to look up the appropriate view. The ServletDispatcher dispatches control to the view component, which can be any view framework (for example, JSP or Velocity), or it can be an action chain, which will execute another action. The view extracts information needed from the value stack. The framework maintains this construct by caching information from both actions and model beans for use by the view. The value stack is discussed in "The Expression Language" section.
On the surface, WebWork looks just like the architectural diagram for Struts. However, the details of information flow are different. WebWork makes accessing information kept in actions and model objects easier by handling much of the information transport for you. WebWork includes numerous custom JSP tags that are savvy about the information flow within the framework.
Validation is also handled differently in WebWork. It allows you to create metadata classes around standard HTML controls to handle formatting, validation, and other facilities. In this regard, the HTML elements become much more like desktop user interface (UI) widgets.
Each of these properties files is loaded from the classpath. You can place them anywhere on the classpath (including the classes directory under WEB-INF in the Web application). One of the properties in both the default and webwork properties files is webwork.configuration.properties, which points to all the other properties files. If you want to store most of the properties files in another location, you can point to that location from this property in the main configuration file. The framework looks for and tries to load both the default and webwork files upon startup. All the other files can load based on property settings in one of the two main files. Developers sometimes like to keep all configuration files together and away from the output classpath, so WebWork facilitates that design via its property-loading mechanism.
Some of these files may also be XML files. In particular, WebWork includes a document type definition (DTD) to use with an XML document for view mappings. If you prefer to keep view information in XML, WebWork can support that. The webwork.configuration.xml property in the webwork properties file allows you to specify an XML view file instead of the standard properties file.
To make it easier for you to set up the directory and configuration file structure WebWork expects, the framework install includes a "skeleton" project named skeleton-project.zip that resides in the /etc directory. This zip file includes a reasonable directory structure, libraries, an Ant build file, templates, and configuration files. This is an excellent starting point for building a WebWork project rather than setting it up on your own.
www.javaworld.com
|
|
|
|
|
Copyright © 2003 - 2008 URL.biz. All rights reserved. |
|