Installation
The process of installing Struts and Stripes are almost similar. Both frameworks require their related .jar files to be included in the application server's classpath or the lib directory of the application. The web.xml file or the container needs to be modified to add the entries for the StripesFilter and the StripesDispatcher. Struts requires the additional step of creating a struts-config.xml file. Stripes will auto discover the action beans and create the config file by itself.
Developing the application using Stripes changes very few things. The application flow remains the same. In fact, the only things that change are the taglibs and the configuration (or the lack of configuration). To see the differences in the code, start with the main JSP page of both applications.
JSP Changes
Stripes comes with its own tag libraries, so the way they are included is different in both frameworks.
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%>
The Struts application uses the <html:form tag> to render an HTML form and the form action to configure an ActionMapping in the struts-config.xml. The Stripes application uses the <stripes:form> tag and sets the action as /stripeshello/actionbeans/GreetUser.action.
Struts has its own tags to render HTML form controlslike the <html:text property="name" /> tag, which renders a text field. In Stripes, you use the <stripes:text name="name" id="index.name" /> tag. Both tags have the same functionality in that they render an HTML 'input text' tag while allowing for localized messages. The <html:submit> tag from the Struts version compares to the <stripes:submit> in Stripes. Just like in Struts, the name attribute of the <stripes:submit> tag plays a very important role in determining the action that will be invoked. One major difference between the frameworks is the way the attributes for the form elements are defined; Stripes tries to stay close to the HTML specification, while Struts has its own attributes.
<stripes:submit name="welcome"><fmt:message key="index.button.submit"
bundle="${stripesMessages}" /></stripes:submit>
Action Bean Changes
So far, the differences between these frameworks have been minimal, but the action bean is where Struts and Stripes really diverge. Struts has Action and ActionForms while Stripes only has ActionBeans. The Stripes ActionBean combines the roles of both Struts' Action and ActionForms classesnamely, transferring data between the view and the model layers and processing that data. Struts requires you to extend the Action and ActionForms classes with the Struts Action and ActionForms classes and therefore you cannot extend any other class if you need to. The Stripes framework improves upon this by making ActionBean an interface. This makes it easier to extend the Action bean from any class. The Action bean also includes a getter and setter for the members, which is equivalent to the UserForm.java (ActionForm) in the Struts version.
Similar to Struts, Stripes provides access to the context through the getContext and setContext methods. The ActionBeanContext provides access to the Servlet API and all the variables in the Request, Response, and Session scopes.
The welcome method is similar to the execute method of the Struts action class. This is where the actual processing of data from the view is handled. After the processing is complete, it returns a Resolution object, which is basically the result of 'handler' methods. There can be any number of handler methods in an ActionBean. The runtime knows that the welcome method is a handler method through the name attribute of the <stripes:submit> tag in index.jsp. The name 'welcome' matches the name of the method. Stripes uses this name to find a handler method for the submit event. Next, you create and return a Resolution, which, in this case, is a ForwardResolutionto forward the request to greeting.jsp.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|