http://www.developer.com/design/article.php/3530776/Working-with-the-WebWork-Framework.htm
Currently, the Java development front is split into two main areas: Web development and Swing client-side GUI development. The Swing developers use the excellent Swing toolkit and core Java APIs for the majority of their GUI development needs. Java Web developers also use core Java APIs, but in addition they use frameworks. Most of the enterprise-level, Web-based projects use some sort of an architecture that includes at least one framework. Why? This is because frameworks greatly simplify development and design of the project, decrease time to production, reduce amount of labor and code needed, and improve application performance. I've described several major frameworks in my previous article "Modern Frameworks for Web Development." This article will concentrate only on WebWork. I will show how to set up WebWork using enterprise-scale tools such as JBuilder 2005 and BEA WebLogic and, as an example, create a sample application that uses some of WebWork's features. I will assume you have WebLogic (or a comparable application server) installed and configured and are familiar with JBuilder IDE. Because WebWork is J2EE-compliant, other application servers, such as Apache Tomcat can be used as well. Every framework for Web developments by design serves a specific purpose. It could be a Model-View-Controller implementation with Inversion of Control logic for coordination of client to server requests and actions on the server, separation of business logic from view layer, or Java to SQL mapping to abstract interaction with database layer. Also, it could be client data validation and view abstraction via custom framework tag libraries and JSTL (Java standard tag libraries). WebWork is a Model-View-Controlled type of framework. This means it separates logic from view and simplifies Web development by using a powerful "action" concept on the server side. It is built on top of a command pattern framework API called XWork. WebWork specific features include: dispatchers that handle/delegate requests; result types that support several view technologies (JSP, Velocity, JasperReports, XML, FreeMarker); and a small but powerful library of JSP tags and Velocity macros. Dispatchers invoke specified XWork actions that access and manipulate the model and provide easy access for the view to display model data. To get started with WebWork, download it here: http://www.opensymphony.com/webwork/download.action.
In JBuilder 2005, configure an enterprise server to point to your BEA WebLogic installation. If you are using a different app server, the setup should be similar. The WebLogic domain and server should be set up and are beyond the scope of this article. Skip this section if you already have configured any application server in you IDE. To show the WebWork framework in action, I created a sample project "WebWork" in JBuilder. To the project libraries (under project properties), I added WebWork jars. The main jar as of this writing is version 2.1.7 I placed and all other libraries in WebWorkLibs and WebWorkOptionalLibs folders. In the project, I added a package called "webwork_test" and there I created an action class HelloAction that extends ActionSupport. ActionSupport is a parent class that all action classes must extend and implement the "execute" method. This action class will be invoked when the client initiates a request with the action name mapped in the configuration file (more on this later). The class simply has two data String variables—greeting and name—and getter and setter methods for them. In the execute method, greeting is set and name is checked because its value will come from the client's request. In addition to the package, I created a Web archive (WAR) module "WebWorkWebModule" in JBuilder, using the Web module wizard under the File -> New menu. In addition to the standard J2EE Web application configuration XML files, WebWork uses several config XML property files to coordinate requests, validate data, and manage data flow. The main ones are xwork.xml and valuators.xml. They need to be put in the servlet container root path for the framework to see them at runtime. I placed these files in the project root directory on the hard drive and added them in JBuilder using properties of the Web module. Right-click on the new Web module. Select the properties' open content section and use the Add Files button to add these files to the build process. The xwork.xml defined my action and which class to use to perform it, and what to do in the event of success or failure. I took the valuators.xml from the WebWork distribution. Please see the attached project for its source. To configure the main controller/dispatcher of the framework, I had to edit the standard web.xml file created with the Web module by JBuilder and located under the WEB-INF directory. The final result looked like this: After the module was created, I placed the WebWork tag libraries descriptor TLD file (that comes with the distribution) in the WEB-INF directory, Now I was done with the configuration! To test the framework in action, I created two JSP files: index.jsp and success.jsp. They both use the WebWork tag libraries to work with data presentation and flow. Below is the source for the index jsp. I indicated that my action is helloAction in the form action parameter and created an input field with name "name". If you recall, the action class looks for this variable in its execute() method. The success.jsp is more interesting because it uses WebWork tag libs and gets values from the response. Here is the working version In this article, I have shown how to set up and configure a project with the WebWork framework. I have also shown a sample application that uses actions and accesses an action's property using tags. This approach can (and should) be expanded when developing your applications. The WebWork framework provides a powerful mechanism for building robust Web applications that I only began to discuss here. The framework has a lot more features to offer for building robust Web applications. If you are looking for a Java Web development framework, you definitely should consider WebWork. Wikipedia online: http://en.wikipedia.org/wiki/ http://e-docs.bea.com/workshop/docs81/doc/en/core/index.html WebWork: http://www.opensymphony.com/webwork/ Vlad Kofman is a Senior System Architect working on projects under government defense contracts. He has also been involved with enterprise-level projects for major Wall Street firms and the U.S. government. His main interests are object-oriented programming methodologies and design patterns.
Working with the WebWork Framework
August 29, 2005
WebWork
Setup Server Environment in JBuilder
The Configure Servers dialog box appears. (See below)
JBuilder provides default settings for the selected server. If JBuilder's default settings are not appropriate, edit any of the settings as needed. Some servers require you to enter settings in addition to the defaults. Clicking the OK button in this dialog box when not all required values are set or selecting another server while the current one is enabled displays a message dialog box that informs you about the missing settings.

Click here for a larger image.

Click here for a larger image.
Set up the project with WebWork

Click here for a larger image.
package webwork_test;
import com.opensymphony.xwork.ActionSupport;
public class HelloAction
extends ActionSupport {
String greeting;
String name;
public String execute() throws Exception {
greeting = "Aloha! ";
if ( (name == null) || (name.length() == 0)) {
return ERROR;
}
return SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGreeting() {
return greeting;
}
}

Click here for a larger image.


Click here for a larger image.
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<!-- Include webwork defaults (from WebWork JAR). -->
<include file="webwork-default.xml" />
<!-- Configuration for the default package. -->
<package name="default" extends="webwork-default">
<!-- Default interceptor stack. -->
<default-interceptor-ref name="defaultStack" />
<action name="helloAction"
class="webwork_test.HelloAction">
<result name="error"
type="dispatcher">index.jsp</result>
<result name="success"
type="dispatcher">success.jsp</result>
</action>
</package>
</xwork>
Note: The main WebWork dispatcher servlet mapping and the reference to tag libraries and mapping of all actions URL pattern to the servlet URL.
<web-app>
<display-name>My WebWork Application</display-name>
<servlet>
<servlet-name>webwork</servlet-name>
<servlet-class>com.opensymphony.webwork.dispatcher.
ServletDispatcher</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webwork</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>
/WEB-INF/lib/webwork-2.1.7.jar
</taglib-location>
</taglib>
</web-app>

Index.jsp
<html>
<head>
<title>WebWork in Action</title>
</head>
<body>
<p>Click the button below to activate HelloAction.</p>
<form action="helloAction.action" method="post">
<p>
<p><input type="text" name="name"/><input type="submit" /></p>
</p>
</form>
</body>
</html>
<%@ taglib uri="/WEB-INF/webwork.tld" prefix="ww" %>
<html>
<head>
<title>WebWork in Action result</title>
</head>
<body>
<ww:property value="greeting" /><ww:property value="name" />
</body>
</html>


Conclusion
References
About the Author