Extending Model Components
Because the Struts framework doesn’t provide a great deal of components for the model layer, extensions to these components are better discussed in other Java programming books. However, there are two classes that might be placed into the category of extensible model components. They aren’t the best representations of what a model component is, but they are responsible for holding model state.
The UserContainer and ApplicationContainer Classes
I’ve mentioned the
UserContainer
and
ApplicationContainer
classes in previous chapters
without defining exactly what they are. These two classes are not
part of the Struts framework—I created them as part of the
example Storefront application. The purpose of these classes is to
store user and application-specific information in instances of these
classes, rather than in the HttpSession
and
ServletContext
objects, respectively.
One of the problems with storing data in the
HttpSession
is that the interface to store and
retrieve data from the session object is not strongly typed. In other
words, the interface for any data is:
public void setAttribute( "permissionsKey", permissions ); public Object getAttribute( "permissionsKey" );
The client must be aware of the key at which the data is stored in order to put an object into or retrieve an object from storage. Some programmers prefer a more strongly typed interface instead:
userContainer.setPermissions( permissions ); userContainer.getPermissions( );
Here, the client ...
Get Programming Jakarta Struts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.