FredTek

Custom Classes

In order to develop custom classes for NetDynamics, there are some important things to know. The full source of a minimal sample custom class is available for download.

Storing Custom Classes

Custom classes should be located in a package in a directory that is accessible through the CLASSPATH. Typically, I store custom classes in the NetDynamics project directory.

Register for appropriate event

Make sure that your custom classes register for the appropriate event Each NetDynamics event handler receives an event object. If you look at the Javadocs for the event object, you will see general information about the event. After that, there are links for the related classes. Typically, one of these classes will be ISp???? (names vary based on the event). If you follow the link for that, it will show you (but not necessarily explain) the method for registering the class for the listener. The example implements the ISpDisplayListener because the onBeforeDisplayEvent receives a CSpDisplayEvent object.

Registering for the appropriate event must be done in the init() method, since it is on each object instance as ND brings it into a project context.

Customized event handlers

If your superclass contains a customized event such as onBeforeHtmlOutputEvent, you have to be careful about customizing the onBeforeHtmlOutputEvent for instances of that object. For a page or data object, ND uses java introspection to detect methods whose signatures conform to a certain format, and then adds listeners using an default adapter.

Exit the event handler properly

Throwing a CSpSkipException in the custom class instead of returning a CSpFileBased.SKIP.

Making changes to custom classes

After making changes to custom classes, make sure that the class is reloaded in the CP. Simply clearing ND cache won't do the job. Restarting the CP service (or the entire ND server) will force the changes to be reloaded.