Adding html to all portal iViews responses – Portal document hooks

The Portal Runtime has defined some points during the request cycle where you can add your own processing. Those entry points, which are called hooks , are defined by the connection and are run for every request.

In this blog post you can find demo code on how to add any html content to portal responses of all portal iViews. We will use document hooks which are executed before and after construction of HTML document. This enables us to add html to different parts of html page (body,head).

*Important note – Hooks affect every request to the portal, and are designed for special situations. Because hooks can have wide-ranging and dangerous side-effects that could harm performance or entire portal functionality, it is not recommended for wide usage and only for special conditions that suits.

In the sample code we will include a specific css file for each portal response:

1. For this we need first to create an portal project in our NWDS:

Lets call our project CssHook.

2. Next we will create a portal service using the NWDS wizard, by right click on the project, then new–>Potal Application , and selecting Portal service:

We will call our service PortalCssHook, with package myPackage.

After few clicks on Next, you will get portal service interface and java implementation template ready.

3. For turning our service into a real document hook, we need to extend our interface (IPortalCssHook) to inherit the IDocumentHookListener: