J2EE Design Pattern : Presentation Tier Patterns : View Helper Design Pattern
|View Helper Design Pattern?|
View Helper encapsulates logic that is not related to presentation formatting into Helper components
Reduce the amount of presentation logic coded directly into the view
- Retrieval of data to display (e.g. from the model)
- Presentation logic (e.g. hiding information)
- General logic (e.g. iterating, etc)
To Adopt the View Helper pattern
- Implement logic as JavaBeans or, preferably, as JSP standard actions or custom tags
- Provides separation between content and presentation of that content
- Can provide a more natural interface to the page author
- Eliminates a “copy and paste” style of reuse
Presentation tier changes occur often and are difficult to develop and maintain when business data access logic and presentation formatting logic are interwoven. This makes the system less flexible, less reusable, and generally less resilient to change.
Intermingling the business and systems logic with the view processing reduces modularity and also provides a poor separation of roles among Web production and software development teams.
The system creates presentation content, which requires processing of dynamic business data.
A view contains formatting code, delegating its processing responsibilities to its helper classes, implemented as JavaBeans or custom tags.
Helpers also store the view’s intermediate data model and serve as business data adapters.
Non-software View Helper Example
View Helper Class Diagram
Participants and Responsibilities
A view represents and displays information to the client. The information that is used in a dynamic display is retrieved from a model. Helpers support views by encapsulating and adapting a model for use in a display.
A helper is responsible for helping a view or controller complete its processing. Thus, helpers have numerous responsibilities, including gathering data required by the view and storing this intermediate model, in which case the helper is sometimes referred to as a value bean. Additionally, helpers may adapt this data model for use by the view. Helpers can service requests for data from the view by simply providing access to the raw data or by formatting the data as Web content.
|Example of View Helper|