This is a presentation given to the Central Iowa Java Users group in 2003. (The technology here is thus a little dated - but it's nice to have this one archived.)
for providing food to our user group meeting! As always, any presentation/meeting suggestions are welcome: [email protected] A thought we had: A meeting consisting of “shorter” (20 min?) presentations to introduce new tech, brief overviews.... Before we begin.... Thursday, September 6, 12
Struts Application Messages/Internationalization Additional Complimentary Tech. (if time allows) Along the Way: Tools, Tips, Best Practices Roadmap Thursday, September 6, 12
(Compare CFM/ASP) Frameworks define re-usable components to make this job easier. A good framework defines how components work to create a usable application. Why Frameworks? Thursday, September 6, 12
choose from. A mature framework can provide functionality that while not “hard to implement”, YOU won’t have to. A note of caution: When adopting a framework, you are adopting a MENTAL MODEL of application development. GET TO KNOW YOUR MODEL! Adopting a Framework Thursday, September 6, 12
event notification mechanism, XMLC (http://barracuda.enhydra.org) WebWork - A framework based on a view “pulling” data from a model (http://mav.sourceforge.net) Jakarta Turbine - A Servlet-Based Framework (http://jakarta.apache.org/turbine) Building Your Own (!!) Important Point: Do your research! Alternative Frameworks Thursday, September 6, 12
Tasks Use Servlets for Programmatic Tasks Similar to Smalltalk MVC (and in other ways, Swing/GUI development) Goal of Struts: Provide a simple, extensible framework for Model 2 Web Application Development. Forward to the Past! Thursday, September 6, 12
(Actions) Can Unit Test at this Level User Interaction (JSPs/ActionForms) Built-In Validation Mechanisms Built-In Internationalization Mechanism What Does Struts Provide? Thursday, September 6, 12
defining re-usable JSP Layouts (The “Tiles” framework) A flexible view mechanism Example: Velocity Templates/XSL Methods Java Standard Tag Library (JSTL) Interoperability w/ other Jakarta Projects Thursday, September 6, 12
is “Ready For Prime Time” Important New Features of Release 1.1 Several “Commons” Packages Created Integrated Tiles Layout Framework Support for Multiple Application Modules! Application can be “divided” into several sub applications Some New Features... Thursday, September 6, 12
(not unique to Struts): Directory Structure Building and Deploying (Tools: Ant/Tomcat) Unit Testing (JUnit/StrutsTestCase/?) Application Logging Development Environment? Developing An Application Thursday, September 6, 12
Action Mappings, Form Definitions, etc. The Struts Configuration File can be confusing and difficult to maintain! Solution: Struts Console! http://www.jamesholmes.com/struts Other Alternatives: Check “Resources” Struts Configuration Thursday, September 6, 12
that does the “work” of the application. Can be complicated, or very simple Struts has several “built in” actions First Example: An “entry” action to a login screen. Developing A First Action Thursday, September 6, 12
Establish a User Session Solution: Develop a “LogonAction” that takes input from a form, and performs validation. Executing a Task Thursday, September 6, 12
using HTML tools. (e.g. Dreamweaver) Struts Provides Custom Tags to Interact with the ActionServlet (thus, Actions) Interaction between JSP and Action is represented by an “ActionForm” Struts View Components Thursday, September 6, 12
forms, links, images, etc. with Struts environment <bean:.../> A way to interact with JavaBeans, or Struts Resources Struts Custom Tags Thursday, September 6, 12
Enter into a JSP) Creating ActionForms Create an object that extends ActionForm Use a “DynaForm” (Essentially, a hash) Struts ActionForm Thursday, September 6, 12
Implement validate() method Use the Commons Validator Framework! ... do not have to be coded. The new Struts 1.1 “Dyna” forms essentially provide hash- like functionality. Dyna Forms can be coupled with Validator Framework! ActionForms... Thursday, September 6, 12
to enter data that is valid to your application. Typically broken into functional validation and application validation. Functional Validation: Override ActionForm.validate() Use the included Validator Framework Validating Form Data Thursday, September 6, 12
model! Struts “Action” classes perform interaction with model, HTTP environment Think of Action classes as acting in the classic “Façade” pattern of Gamma, et. al. An Action takes input, submits to the model, then “takes action” on the result. Interacting With Model Components Thursday, September 6, 12
Views: Use Custom Tags! Take Care: Extending the Framework in “unusual” ways may interfere with upgrading to newer versions of the framework! Example: Several Struts 1.0 Applications extend the ActionServlet class itself Extending the Framework Thursday, September 6, 12
or fields, etc...) Advantage: Internationalization! Struts has a ‘default’ Resources File, but you can also create international files by registering Domain/Language files (e.g. Resources_en_US.properties) What’s Happening? Thursday, September 6, 12
is thrown. Can be global or Action-based Can either be a simple forward, or passed to a custom error handler class. Application Exceptions Thursday, September 6, 12
Create a template that contains holders for variables. These variables are other documents (JSP/HTML/Text) that can be placed in the main layout Tiles adds functionality to “<jsp:include/>” Re-usable layouts make design much simpler! Tiles is included with Struts Distribution! Tiles Layout Framework Thursday, September 6, 12
layouts simpler. Definitions can be either in JSPs, or in an external XML definition. Definitions can also be extended, or overridden. http://www.oreilly.com/catalog/jakarta/ chapter/ch14.pdf (free!) Tiles Definitions Thursday, September 6, 12
define reusable validation rules. (e.g. What is a valid e-mail address?) The Validation Framework Relies on two configuration files validation.xml: Ties rules to application validator-rules.xml: Defines Rules! Thursday, September 6, 12
“required”, “minLength”, “maxLength”, etc.) Custom Validation rules can be created and added to the definition file. A big feature: The built-in validation rules come with Javascript that allows you to “turn on” client side validation! Thursday, September 6, 12
having a properly developed Unit Test suite. Testing Tools: JUnit (http://www.junit.org) StrutsTestCase (http:// strutstestcase.sourceforge.net) HttpUnit (http://httpunit.sourceforge.net) JWebUnit (http://jwebunit.sourceforge.net) Unit Testing Thursday, September 6, 12
Struts, etc.) are testing my entire application? (i.e. What Tests have I missed?) Commercial Code Coverage Tools Clover (http://www.thecortex.net/clover/) JProbe (http://java.quest.com/jprobe/ jprobe.shtml) Unit Test Coverage Thursday, September 6, 12
proven logging tool that is configuration-based. (http://jakarta.apache.org/log4j) For those that can’t decide: Jakarta Commons Logging (http://jakarta.apache.org/commons/logging) Application Logging Thursday, September 6, 12