The Web Graph Database


Viewlet Framework : Creating a Custom Viewlet

Creating a custom Viewlet is identical to creating a JSP-only Viewlet, except that a custom Viewlet defines its own backing Viewlet class.

By convention, the name of the class is the same as the name of the Viewlet and the same as the name of the JSP file, minus the extensions. For example:

  • Viewlet name: com.example.viewlet.CustomerViewlet
  • JSP file name: v/com/example/viewlet/CustomerViewlet.jsp
  • Backing class name: com.example.viewlet.CustomerViewlet.

The backing class must implement JeeViewlet, which is most easily accomplished by inheriting from AbstractJeeViewlet.

To add the custom Viewlet to the ViewletFactory, use code such as:

    if( subject.isBlessedBy( CustomerModelSubjectArea.CUSTOMER )) {
        ret.add( CustomerViewlet.choice( ViewletFactoryChoice.GOOD_MATCH_QUALITY ));

where the CustomerViewlet.choice method is implemented similar to:

    public static ViewletFactoryChoice choice(
            double matchQuality )
        return new DefaultViewletFactoryChoice( CustomerViewlet.class, matchQuality ) {
                public Viewlet instantiateViewlet(
                        MeshObjectsToView        toView,
                        Context                  c )
                    return new CustomerViewlet( c );

See also:

Last modified 9 years ago Last modified on 07/24/09 18:25:38