O'Reilly logo

Programming Jakarta Struts, Second Edition by Chuck Cavaness

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Struts View Components

The last of the MVC components to discuss are the view components. Arguably, they are the easiest to understand. The view components typically employed in a Struts application are:

  • HTML

  • Data transfer objects

  • Struts ActionForms

  • JavaServer Pages

  • Custom tags

  • Java resource bundles

Using the Struts ActionForm

Struts ActionForm objects are used in the framework to pass client input data back and forth between the user and the business layer. The framework automatically collects the input from the request and passes this data to an Action using a form bean, which then can be passed along to the business layer. To keep the presentation layer decoupled from the business layer, you should not pass the ActionForm itself to the business layer; rather, create the appropriate DTO using the data from the ActionForm. The following steps illustrate how the framework processes an ActionForm for every request:

  1. Check the mapping for the action and see if an ActionForm has been configured.

  2. If an ActionForm is configured for the action, use the name attribute from the action element to look up the form bean configuration information.

  3. Check to see if an instance of the ActionForm already has been created.

  4. If an ActionForm instance is present in the appropriate scope and it’s the same type as needed for the new request, reuse it.

  5. Otherwise, create a new instance of the required ActionForm and store it in the appropriate scope (set by the scope attribute for the action element).

  6. Call the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required