next up previous contents
Next: Composite views Up: Abstracting data views Previous: Abstracting data views   Contents

Adding a view

Suppose the class User has grown to 40 different fields, but we want a lookup of several users to pass to someone(maybe the list of users at a company). Now what if all that was needed was the name, Id and email of each user. If the list is hundreds long and we are Serializing (or marshaling to XML) all 40 fields for each user, we are seriously hurting performance.

The solution is to pass only the fields we need in Views of the User. to do so we do the following

<property name="views.pkg" value="org.ephman.examples.user.views"/>

<class name="${user.pkg}.User" ... >

    <class-view name="${views.pkg}.UserQuickView"
format="quick" />
    <field name="userId" type="string">
      <view in="quick"/>
This will generate a class representing an abstraction of the class User, which has the field userId. ALSO a routine will be added to User called createQuickView (). This routine operates on this and returns a UserQuickView with userId set to the same value in the User object. Also you can create a new User with a UserQuickView as the initialization parameters (ie. from a new User form).
UserQuickView initUser -> passed in from a separate service..
User newUser = new User ();
newUser.initializeFromView (initUser);