|
|
As the view implementations we've discussed demonstrate, it's easy to implement the View interface, especially if we subclass the com.interface21.web.servlet.view.AbstractView convenience class.
A custom view implementation can integrate with almost any view technology. We simply need to provide an implementation class, which might be generic or application-specific, and provide a view definition using the standard JavaBean syntax.
The power of the basic approach is shown by the fact that a View implementation could easily be written for each of the following, without any need to change controller or model code in the application concerned:
A view that causes an XSLT transform to be performed in the client browser (rather than on the server) exposing XML and stylesheet.
A composite view that includes the output of other views, possibly even using different technologies.
A forwarding view that looks at the user agent string returned by the browser and chooses a delegate view accordingly (for example, if the browser is known to be capable of performing XSLT transforms, control could be passed to a view that initiates a client-side transform; otherwise the XSLT transform could be performed on the server, returning the generated output to the client).
A custom view that uses a class library to generate an Excel spreadsheet for numeric model data.
Important | Using the approach described here, we can define a view for anything that can take model data and generate output. If necessary, we can convert model data into a form other than Java objects. |
|
|