Apache Struts 2.0, JAVA EE, Open Source
Upcoming SlideShare
Loading in...5

Apache Struts 2.0, JAVA EE, Open Source



Apache Struts is an open-source web application framework for developing Java EE web applications.

Apache Struts is an open-source web application framework for developing Java EE web applications.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Apache Struts 2.0, JAVA EE, Open Source Apache Struts 2.0, JAVA EE, Open Source Presentation Transcript

  • Struts
      • Omprakash Pandey
      • [email_address]
      • http://www.synergetics-india.com
      • Videos: http://www.youtube.com/thesynergetics
    • Minimize Java Code in JSP
      • Separation of concerns (web designer/Java developer)
    • Use include mechanisms
      • Include directive: <%@ include file=&quot;filename&quot; %> : static inclusion when pre-processing JSP
      • Include action: <jsp:include page=&quot;page.jsp&quot; flush=&quot;true&quot; /> : dynamic execution of request by included resource
    • Do not mix business logic with presentation logic
        • Separate responsibilities
        • Better maintainability
        • Better composition
    Web Interface Best Practices
    • Use JSP custom tags (may have to develop these)
      • Eliminate Java code from HTML
      • Easier syntax
      • Improve web designers productivity
      • Elements of reusable code
      • Suggestions:
        • Keep tag syntax simple (fewer attributes)
        • Do not re-invent a wheel
    Web Interface Best Practices
  • Web Interface Best Practices
      • Place business logic in JavaBeans
      • Do not use logic in custom tags that is not user interface-specific
      • Use MVC pattern
      • Use XHTML syntax
    • Use Servlet filters for common tasks
      • Common login
      • Compression
      • Authentication/Authorization
    • Create a portable security model
      • If cannot avoid vendor security model
    • Cache results from DBMS in RowSets
    Web Interface Best Practices
    • Frameworks:
      • Provides abstraction of a particular concept
      • Defines how these abstractions work together to solve a problem
      • Framework components are reusable
      • Organizes patterns at higher level
      • Provides generic behaviour (many different applications can be built with the use of the same application)
    Power of Frameworks
  • JSP Model 1 Architecture Demo Model 1 example Web Browser JSP JavaBean
  • MVC Pattern View Model Controller Change notification Query state View selection User input Change state events
  • JSP Model 2 Architecture Web Browser JSP JavaBean Servlet Demo Model 2 example
    • Java – based CGI - HTML mixed in Java
    • Servlets – HTML mixed in Java
    • JavaServer Pages – Java code mixed in HTML
    • Servlets + JSP – use of MVC pattern to separate business logic from presentation
    • Frameworks: Tapestry(servlets, it’s own html templates), Struts, JavaServer Faces
    Java Web UI History
    • Framework for building Web applications using Java
    • Builds on MVC pattern
    • Located at: http://jakarta.apache.org/struts/
    • Created in 2000 by Craig R. McClanahan
    • Donated to ASF in 2000
    • Current stable release: 1.3.5
    • Soon (2006) to be released 2.0
    • 1.x will be around - there is new development, great community, many applications are developed in 1.x
    Struts History
    • HTTP Protocol (request/response)
    • HTML
    • The Java Language and Application Frameworks
    • JavaBeans
    • Properties Files and ResourceBundles
    • Java Servlets
    • JavaServer Pages, JSP Tag Libraries
    • XML
    Quick Technology Overview
    • Struts does not specify how to implement Model part of MVC
    • JSP and Struts Tag Libraries used for View part of MVC
    • Struts Controller implemented as: ActionServlet and ActionMapping
    Struts MVC
    • 3 Major Components
      • Servlet controller (Controller)
      • Java Server Pages (View)
      • Application Business Logic (Model)
    • Controller bundles and routes HTTP request to other objects in framework (Actions)
    • Controller parses configuration file
    Struts MVC
    • Configuration file contains action mappings (determines navigation)
    • Controller uses mappings to turn HTTP requests into application actions
    • Mapping must specify
      • A request path
      • Object type to act upon the request
    Struts MVC
    • HTML
    • DTO
    • Struts ActionForms objects
    • JavaServer Pages
    • Struts Tags
    • Custom Tags
    • Java Resource Bundles
    • Other: graphics, downloads, etc.
    View Components
    • ActionForm Beans
      • Extends the ActionForm class
      • Create one for each input form in the application
      • JavaBeans – style properties must match form entries
    View Components Action Forms
    • Continued
      • Define a property (with associated getXxx() and setXxx() methods) for each field that is present in the form. The field name and property name must match according to the usual JavaBeans conventions
      • Place a bean instance on your form, and use nested property references. For example, you have a &quot;customer&quot; bean on your Action Form, and then refer to the property &quot;customer.name&quot; in your JSP view. This would correspond to the methods customer.getName() and customer.setName(string Name) on your customer bean
    View Components Action Forms
    • org.apache.struts.ActionServlet is a main component of Struts
    • org.apache.struts.action.Action – extension of controller component (defined in action mapping in the configuration file)
    Controller Components
    • Struts use configuration file called
      • struts-config.xml
      • This file provides for a configuration of controller components (actions), resources, model components: JavaBeans and other resources
    Controller Components Deployment descriptor for Struts
    • The action mapping example
    • <action-mappings>
    • <action path=&quot;/addBookAction“
            • type=
    • &quot;edu.depaul.struts_example.BookInputAction&quot;
    • name=&quot;addBookBean&quot;
    • scope=&quot;request&quot;
    • input=&quot;/add_book.jsp&quot;>
    • <forward name=&quot;Go&quot; path=&quot;/result.jsp&quot;/>
    • <forward name=&quot;cancel&quot; path=&quot;/index.html&quot;/>
    • </action>
    Controller Components Action mapping name mapping type Form Bean name forward definition
    • System State Beans
    • A set of one or more JavaBeans classes, whose properties define the current state of the system
    • Example: shopping cart
    • In a J2EE application a model is usually encapsulated as a layer of Session Façades
    Model Components
    • Accessing Relational Databases
    • Struts can define the data sources for an application from within its standard configuration file
    • A simple JDBC connection pool is also provided (can be configured in the configuration file)
    Struts Model Components
    • Action Forms are a Java Beans
    • Extends ActionForm class from Struts Framework (makes it dependent on the Struts API)
    • Action Forms are mapped to HTML forms – hence the name
    Struts Action Forms
    • Extend org.apache.struts.action.ActionForm
    • Override:
      • validate() - optional
      • reset() – optional
    • Provide JavaBeans/style properties that match an HTML form input/output values
    Struts Action Forms
    • For every “action” in the application , a custom “Action” is defined
    • These a similar to servlets
    • Short – lived (for the duration of the request)
    • Stateless – do not put any state in the Action classes
    Struts Actions
    • org.apache.struts.action.Action
    • Implementations subclass this class and provide implementation of execute method:
    • ActionForward execute(ActionMapping , ActionForm , HttpServletRequest , HttpServletResponse );
    Struts Action
    • ActionMapping - provides access to the information stored in the configuration file (struts-config.xml) entry that configures this Action class.
    • ActionForm form—This is the form bean. By this time, the form bean has been pre-populated and the validate() method has been called and returned with no errors (assuming that validation is turned on). All the data entered by the user is available through the form bean.
    • HttpServletRequest request—This is the standard JSP or Servlet request object.
    • HttpServletResponse response—This is the standard JSP or Servlet response object.
    Action.execute() Arguments
    • ActionForward represents a destination to which the controller, RequestProcessor, might be directed to perform a RequestDispatcher.forward or HttpServletResponse.sendRedirect to, as a result of processing activities of an Action class.
    • Instances of this class may be created dynamically as necessary, or configured in association with an ActionMapping instance for named lookup of destinations from configuration files
    Action.execute() Return Value: ActionForward
    • SelectAction Determine the ActionMapping associated with this path.
    • CreateActionForm Instantiate (if necessary) the ActionForm associated with this mapping (if any) and place it into the appropriate scope.
    • PopulateActionForm Populate the ActionForm associated with this request, if any.
    • ValidateActionForm Perform validation (if requested) on the ActionForm associated with this request (if any).
    • SelectInput If validation failed, select the appropriate ForwardConfig for return to the input page.
    • CreateAction Create an instance of the class specified by the current ActionMapping
    • ExecuteAction This is the point at which your Action's execute method will be called.
    • PerformForward Finally, the process method of the RequestProcessor takes the ActionForward returned by your Action class, and uses it to select the next resource (if any). Most often the ActionForward leads to the presentation page that renders the response.
    RequestProcessor – the heart of Controller (Chain of Responsibility Pattern )
  • Struts Simple Demo
  • Decomposing Struts Application (web.xml) <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
  • Decomposing Struts Application (index.jsp) <%@ taglib uri=&quot;http://struts.apache.org/tags-html&quot; prefix=&quot;html&quot; %> <%@ taglib uri=&quot;http://struts.apache.org/tags-bean&quot; prefix=&quot;bean&quot; %> <html:form action=&quot;simpleAction&quot; method=&quot;POST&quot;> First Name: <html:text property=&quot;firstName&quot;/> <font color=&quot;red&quot;><html:errors property=&quot;firstName&quot;/> </font> Last Name: <html:text property=&quot;lastName&quot;/> <font color=&quot;red&quot;><html:errors property=&quot;lastName&quot;/> </font> <html:submit value=&quot;Submit&quot;/> </html:form> Note: some HTML tags are omitted for clarity kxx
  • Decomposing Struts Application (SimpleForm.java)
    • Rule: Action forms in Struts must:
    • Conform to the JavaBeans property name conventions
    • Action forms properties must correspond to the names defined in a form
    • public class SimpleForm extends ActionForm
    • {
    • private String firstName;
    • private String lastName;
    • public String getFirstName()
    • {
    • return firstName;
    • }
    • ... other getters and setters
    • }
  • Decomposing Struts Application (struts-config.xml part 1) <form-beans type=&quot;org.apache.struts.action.ActionFormBean&quot;> <form-bean name=&quot;simpleBean&quot; type=&quot;edu.depaul.struts.SimpleForm&quot; /> </form-beans>
  • Decomposing Struts Application ( struts-config.xml part 2 ) <action-mappings type=&quot;org.apache.struts.action.ActionMapping&quot;> <action path=&quot;/simpleAction&quot; type=&quot;edu.depaul.struts.SimpleAction&quot; name=&quot;simpleBean&quot; scope=&quot;request&quot; input=&quot;/index.jsp&quot;> <forward name=&quot;next&quot; path=&quot;/next.jsp&quot;/> <forward name=&quot;again&quot; path=&quot;/index.jsp&quot;/> </action> </action-mappings> <!-- This is a reference to a resource bundle with messages. The file name is: struts-examples.properties --> <message-resources parameter=&quot;struts-examples&quot; />
  • Anatomy of a Struts Application Browser Web Container ActionServlet Action Model JSP View 1 2 5 3 4 struts-config DBMS
  • Decomposing Struts Application (SimpleAction.java) public ActionForward execute( ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { //getting posted information SimpleForm simpleForm = (SimpleForm) actionForm; ///... - business – related processing httpServletRequest.setAttribute(&quot;simpleForm&quot;, simpleForm); //passing control to the next page return actionMapping.findForward(&quot;next&quot;); }
    • If action mapping defined in the configuration file, the Controller Servlet/RequestProcessor will perform the following:
    • Check session or request for instance of bean of appropriate class
    • If no session/request bean exists, one is created automatically
    • For every request parameter whose name corresponds to the name of a property in the bean, the corresponding setter method will be called
    • The validate() method of ActionForm is called
    • The updated ActionForm bean will be passed to the Action Class execute() method when it is called, making these values immediately available
    • The execute() method must return an instance of ActionForward – instructing the controller which is the next view (page)
    • The next page is merged with data passed in request or session object, and then renders HTML
    Request Processing
  • Request Processing Web Browser displays page Controller ActionForm Action Model struts-config JSP Page 1 2 3 4 5 6 7 8
    • The <html:html> Tag
    • The <html:html>tag simply generates the <html> HTML element at the beginning of the file. In our case, this is a very basic tag.
    • If this application were written to provide locale-specific text, the tag could have been written as
    • <html:html locale=”true”>
    • Using the local=”true” option causes this page to set its locale value based on the
    • Accept-Language header submitted by the client browser (if a locale was not already
    • set).
    Page Construction html tags
    • The <html:base> Tag
    • The <html:base>tag generates an HTML <base> element in the <head> section of the
    • document. The <base> HTML element is used to assist the client browser in correctly
    • forming relative URL paths if they’re present in the HTML page.
    • In this case, our <html:base/> tag rendered the following HTML:
    • <base href=”http://localhost:8080/appname/mypage.jsp”>
    Page Construction html tags
    • The <html:link> tag provides convenience and a great deal of flexibility if it makes sense for your application to URL encode request parameters. It also automatically handles URL encoding of Session IDs to ensure that you can maintain session state with users who have cookies turned off in their browser.
    • <global-forwards>
      • <forward name=”index” path=”/index.jsp”/>
    • </global-forwards>
    • <html:link forward=”index”>Go Home</html:link>
    • The HTML generated is
    • <a href=”/myapp/index.jsp”>Go Home</a>
    • Create Link by Specifying a Full URL
    • <html:link href=”http://jakarta.apache.org/struts/index.html”>
      • Generate an “href” directly
    • </html:link>
    Page Construction html tags
    • The Basics of Form Processing
    • This section provides information on the following tags:
    • <html:form> - Render an HTML <form> element
    • <html:text> - Text box INPUT element
    • <html:hidden>— INPUT type=hidden element
    • <html:submit>—Place a Submit INPUT element
    • <html:cancel>—Place a Submit INPUT element which can be used to “cancel” workflow
    Form Construction
    • <html:form action=&quot;simpleAction&quot; method=&quot;POST&quot;>
    • ” simplAction” - action name corresponds to action name in configuration
    • <action path=&quot;/ simpleAction &quot;
    • cancellable=&quot;true&quot;
    • type=&quot; edu.depaul.struts.SimpleAction &quot;
    • name=&quot; simpleBean &quot; //– name of bean mapped to form controls
    • scope=&quot;request&quot;
    • input=&quot;/index.jsp&quot; >
    Form Construction <html:form>
    • <html:text property=&quot; firstName &quot;/>
    • Generates HTML:
    • <input type=&quot;text&quot; name=&quot; firstName &quot; value=&quot;&quot;>
    • Bean form bound:
    • public class SimpleForm extends ActionForm
    • {
    • private String firstName ;
    • private String lastName;
    • ...
    Form Construction <html:text/>
    • <html:submit value=&quot;Submit&quot;/>
    • Generates:
    • <input type=&quot;submit&quot; value=&quot;Submit&quot;>
    Form Construction <html:submit/>
    • <html:select property=&quot; address &quot;>
      • <html:option value=&quot;Please, make selection&quot;/>
      • <html:options property=&quot; addresses &quot;/>
    • </html:select>
    • Where
    • address is a form bean property which will be set with a selected value
    • addresses – Collection type property for inputs
    Form Construction <html:select>
    • Validation can be provided:
      • FormBean.validate(ActionMapping mapping, HttpServletRequest request)
      • Directly in the Action.execute() method:
      • ActionMessages actionMessages = new ActionMessages();
      • if (simpleForm.getFirstName() == null ||simpleForm.getFirstName().equals(&quot;&quot;))
      • {
      • actionMessages.add(&quot;firstName&quot;, new
            • ActionMessage(&quot;field.required&quot;));
      • }
    Input Validation
  • Input Validation
      • if (!actionErrors.isEmpty())
      • {
      • saveMessages(request, actionErrors);
      • return actionMapping.getInputForward();
      • }
      • getInputForward(); -> sends back name of a page from which the Action was invoked
    • Struts converts data according to property data type
    • If typed value cannot be converted to appropriate type, then exception is thrown
    • Exception cannot be intercepted – happens before validation
    • Best practice: all properties are Strings
    Strings in ActionForm
    • Resource Bundle specified in a struts-config file:
    • <message-resources parameter=&quot;struts-examples&quot; />
    • Simple Java properties file:
    • message_key=Message Text
    • Easy to do I18N
    Message Configuration
    • <html:errors> - outputs all error messages
    • <html:errors property=”propName”> - outputs a message for property “ propName ” if one exists
    Message Output
    • Page Global Messages:
    • Adding:
    • messages.add(ActionMessages.GLOBAL_MESSAGE,
    • new ActionMessage(“this.message.key”) );
    • Displaying:
    • <html:messages property=
    • ” org.apache.struts.action.GLOBAL_MESSAGE”/>
    Global Messages
    • public class UploadForm extends ActionForm
    • {
    • private FormFile file;
    • ... - setter and getter
    Uploading Files form bean
    • <html:form action=&quot;/uploadAction&quot; enctype=&quot;multipart/form-data&quot;>
    • Please select local file:<br/>
    • <html:file property=&quot;file&quot;/>
    • <html:submit/>
    • </html:form>
    Uploading Files jsp
    • UploadForm form = (UploadForm)actionForm;
    • FormFile formFile = form.getFile();
    • byte data[] = formFile.getFileData();
    • //now that you have data, you can act on the //contents of a file
    Uploading Files action
    • The <bean:cookie> tag retrieves a cookie or cookies sent to the server from thebrowser.
    • The <bean:header> Tag - provides access to the HTTP header
    • The <bean:parameter> tag enables you to explicitly get a parameter passed into this page (either by a form submit or by arguments in the URL).
    • The <bean:page> Tag: to gain access to the request, session, response, Struts config, or application data. The id attribute must be one of the strings “ request ”, “ session ”, “ config ”, “ response ”, or “ application ”).
    Bean Tags
    • <bean:cookie id=”cookie” name=”/tags/cookiedemo” value=”firsttime”/>
    • <bean:write name=”cookie” property=”value”/>
    • <bean:header id=”lang” name=”Accept-Language”/>
    • The preferred language for this browser is: <bean:write name=”lang”/>
    • <bean:parameter id=&quot;bean1&quot; name=&quot;bean1&quot; />
    • <bean:write name=”bean1” property=”name”/>
    • <bean:page id=”this_session” property=”session”/>
    • Session Created =
    • <bean:write name=”this_session” property=”creationTime”/>
    Bean Tag Examples
    • <bean:message key=&quot;welcome.user&quot; arg0=&quot;${user.username}&quot; />
    • ${user.username} – JSP 2.0 EL expression
    • Resource Bundle:
    • welcome.user={0}, welcome to Acme Books
    Bean Tag bean:message
    • <bean:resource id=&quot;webxml&quot; name=&quot;/WEB-INF/web.xml&quot;/>
    • Gets contents of a resource and assigns it to a parameter with id=”webxml”
    Bean Tag bean:resource
    • org.apache.struts.action.DynaActionForm
    • config:
    • <form-bean name=”userForm” type=”org.apache.struts.action.DynaActionForm”>
      • <form-property name=”userId” type=”java.lang.String” initial=”admin”/>
      • <form-property name=”password” type=”java.lang.String”/>
    • </form-bean>
    • No need to write any Java.
    • Validation? There is no validate() method.
    • Solution1: validate in Action
    • Solution 2: sub-class the DynaActionForm class and add a validate () method
    • Solution 3: Use validation framework
    • Disadvantage: not type safe, typos can lead to hours of debugging (no Compile time type checking)
    • execute(...)
    • {
    • DynaActionForm myForm = (DynaActionForm )form;
    • String name = (String)myForm.get(“name”);
    • }
    DynaActionForms inside Action
  • Validation Framework
    • Jakarta Commons Validator Framework
      • http://jakarta.apache.org/commons
    • Deployed as a Struts Plugin
    • Extended by Struts to provide generic validation rules
    • Common Rules:
      • check for required fields
      • check for max/min size
      • check for the right data type
    Validation Framework
    • required – field data provided
    • minlength – more than min length
    • maxlength – less than max length
    • range – in range of values
    • mask – correct format (takes regexp)
    • date – validates correct date format
    • email – validates correct E-Mail fromat
    • primitives: byte, integer, float, double , etc.
    Validator Built-in Rules
    • <plug-in
    • className=&quot;org.apache.struts.validator.ValidatorPlugIn&quot;>
      • <set-property
        • property=&quot;pathnames&quot;
    • value=&quot;/org/apache/struts/validator/validator-rules.xml, /WEB-INF/validation.xml&quot;/>
      • <set-property
          • property=&quot;stopOnFirstError&quot;
          • value=&quot;true&quot;/>
    • </plug-in>
    Validator Setup
    • validation-rules.xml – contains all possible rules
    • validation.xml – contains mappings of forms, properties and rules
    Validator Files
  • Validator Example DynaValidatorForm Configure a dyna-form in struts-config.xml file <form-bean name=&quot;userForm&quot; type=&quot;org.apache.struts.validator.DynaValidatorForm&quot; > <form-property name=&quot;userId&quot; type=&quot;java.lang.String&quot;/> <form-property name=&quot;password&quot; type=&quot;java.lang.String&quot;/> </form-bean> DynaValidatorForm - provides basic field validation based on an XML file
  • Validator Example action mapping <action path=&quot;/validationAction&quot; cancellable=&quot;true&quot; type=&quot;edu.depaul.struts.ValidationAction&quot; name=&quot;userForm&quot; scope=&quot;request&quot; input=&quot;/validation.jsp&quot;> <forward name=&quot;next&quot; path=&quot;/validation-results.jsp&quot;/> <forward name=&quot;cancelled&quot; path=&quot;/index.jsp&quot;/> </action>
  • Validator Example validation.jsp validation.jsp (HTML omitted for clarity – see demo): <html:form action=&quot;validationAction&quot; method=&quot;POST&quot;> User ID: <html:text property=&quot;userId&quot;/> <html:errors property=&quot;userId&quot;/> Password <html:password property=&quot;password&quot;/> <html:errors property=&quot;password&quot;/> <html:submit value=&quot;Submit&quot;/> <html:cancel value=&quot;Cancel&quot;/> </html:form>
    • <form name=&quot; userForm &quot;>
    • <field property=&quot; userId &quot;
          • depends=&quot;required, maxlength&quot;>
    • <msg
          • name=&quot;required&quot;
          • key=&quot; validationForm.iserId.required &quot; />
    • <msg name=&quot;maxlength&quot;
          • key=&quot;validationForm.iserId.maxlength&quot; />
          • <arg0 name=”required” key=”iserId.label”/>
    • <var>
    • <var-name>maxlength</var-name>
    • <var-value>3</var-value>
    • </var>
    • </field>
    • ... other fields
    Validator Example validation.xml action form name property name validated mandatory resource bundle message key
    • Where
    • userForm – name of action form defined in the struts-config.xml
    • userId – name of a form property being validated
    • validationForm.iserId.required – message key from message resource bundle
    • Also:
    • <arg0 name=”required” key=”iserId.label”/>
    • You can have the following in the message bundle:
    • validationForm.iserId.maxlength={0} exceeded maximum length.
    • iserId.label=User Id
    • In this case, the error message returned by the framework in case this
    • field does not pass validation would be:
    • User Id exceeded maximum length.
    Validator Framework validation.jsp
    • var element is used to pass any variables to
    • the validation rule that is being used.
    • minlength minlength
    • maxlength maxlength
    • range min,max
    • mask mask
    • date datePattern
    Validator Framework validation.xml
    • class MyValidatorForm extends DynaValidatorForm
    • {
    • ...
    • public ActionErrors validate(ActionMapping, HttpServletRequest)
    • {
      • super.validate(mapping, request);
      • ...
    • }
    Validator Framework mixing programmatic invocation and XML rules
    • 1. Create class with public static method:
    • someMethod(
    • ValidatorAction, Field, ActionErrors, HttpServletRequest);
    • 2. Provide a new validator definition in the validation-rules.xml file:
      • a. Validator name
      • b. Class name
      • c. Method name
      • d. Signature
    • 3. Can provide JavaScript to validate on client
    Validator Framework Adding new rules(validators)
    • Struts bakes rules directly into Jakarta Validator Framework.
    • Jakarta Framework allows for any method signature, but Struts requires exact signature – dependency in Struts- difficult to reuse validators in a different environment
    • JavaScript can break if user disables JS in client
    • Better to implement validation logic in a framework independent manner (even if using Jakarta Validator) and invoke validations from validate() methods – this will lead to more infrastructure work
    Validator Framework
  • Tiles Integration
    • Tool for creating reusable layouts for sites
    • Open Source Project (ASF)
    • Integrated with Struts
    • Not Enabled by default
    • Allows for tiles definitions in XML
    • Need to define a Tiles plugin in struts-config.xml:
    • <plug-in
    • className=
    • &quot;org.apache.struts.tiles.TilesPlugin&quot;>
    • <set-property
    • property=&quot;definitions-config&quot;
    • value=&quot;/WEB-INF/ tiles-defs.xml &quot;
    • />
    • </plug-in>
    • Close to the end of file with all other plugins
    • Create template JSP(template.jsp):
    • <table border=&quot;1&quot;>
    • <tr> <td>
    • <tiles:insert attribute='header'/> </td></tr>
    • <tr> <td>
    • <tiles:insert attribute='menu'/>
    • </td></tr>
    • <tr> <td>
    • <tiles:insert attribute='content'/> </td></tr>
    • <tr> <td>
    • <tiles:insert attribute='footer'/> </td></tr>
    • </table>
    • Provide Tiles Definitions in the tiles-defs.xml file:
    • <definition name=&quot;.baseDef&quot; page=&quot;/tiles/template.jsp&quot;>
    • <put name=&quot;title&quot; value=&quot;Base Template Page&quot;/>
    • <put name=&quot;header&quot; value=&quot;/tiles/header.jsp&quot;/>
    • <put name=&quot;footer&quot; value=&quot;/tiles/footer.jsp&quot;/>
    • <put name=&quot;menu&quot; value=&quot;/tiles/menu.jsp&quot;/>
    • <put name=&quot;content&quot; value=&quot;/tiles/blank.jsp&quot;/>
    • </definition>
    • <definition
        • name=&quot;.index&quot;
        • extends=&quot;. baseDef &quot;>
      • <put
        • name=&quot; title &quot;
        • value=&quot;New Page Title&quot;/>
      • <put
        • name=&quot; content &quot;
        • value=&quot;/tiles/index.jsp&quot;/>
    • </definition>
    • This definition extends . baseDef and overrides title and content fields
    • Provide Action Mapping in the
    • <action path=&quot;/someAction&quot;
    • ...
      • <forward name=&quot;next&quot; path=&quot;. index &quot;/>
    • ...
    • </action>
    • * Improved design - All Struts 2 classes are based on interfaces. Core interfaces are HTTP independant.
    • * Intelligent Defaults - Most configuration elements have a default value that you can set and forget.
    • * Enhanced Results - Unlike ActionForwards, Struts 2 Results can actually help prepare the response.
    • * First-class AJAX support - The AJAX theme gives your interactive applications a boost.
    • * Stateful Checkboxes - Struts 2 checkboxes do not require special handling for false values.
    • * QuickStart - Many changes can be made on the fly without restarting a web container.
    Looking Ahead Struts 2 - 2006?
    • * Easy-to-test Actions - Struts 2 Actions are HTTP independant and can be tested without resorting to mocks.
    • * Easy-to-customize controller - Struts 1 lets you customize the request processor per module, Struts 2 lets you customize the request handling per action, if you like.
    • * Easy-to-customize tags - Struts 2 tags can be customized by changing an underlying stylesheet.
    • * Easy cancel handling - The Struts 2 Cancel button can go directly to a different action.
    • * Easy Spring integration - Struts 2 Actions are Spring-aware. Just add your own Spring beans!
    • * Easy Plugins - Struts 2 extensions can be added by dropping in a JAR. No manual configuration required!
    Looking Ahead Struts 2 - 2006?
    • * POJO forms - No more ActionForms! Use any JavaBean you like or put properties directly on your Action. No need to use all String properties!
    • * POJO Actions - Any class can be used as an Action class. You don't even have to implement an interface!
    Looking Ahead Struts 2 - 2006?
    • Bottom Line:
    • Integrated with WebWork
    • Breaks backwards compatibility
    • 1.x is deeply entrenched in enterprise
    • JSF is gaining momentum
    • Struts 1.x has been too long in the 1.x mode
    • Is there future for 2.0? - time will tell
    Struts 2.0