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
ActionFormsJavaServer 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:
Check the mapping for the action and see if an
ActionFormhas been configured.If an
ActionFormis configured for the action, use thenameattribute from theactionelement to look up the form bean configuration information.Check to see if an instance of the
ActionFormalready has been created.If an
ActionForminstance is present in the appropriate scope and it’s the same type as needed for the new request, reuse it.Otherwise, create a new instance of the required
ActionFormand store it in the appropriate scope (set by thescopeattribute for theactionelement).Call ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access