> developer > dnu > courses > portal overview page 17
Novell Portal Services Overview and Gadget Development
April 2003
DeveloperNet University Course
Reader Rating    from ratings rate this article
View an eBook Version of this course - LARGE FILE! Send this page to a friend

Advanced Gadget Development

In this section, we will cover advanced topics of Gadget Development. Some of the areas covered will be:

  • Gadget State

  • Gadget Actions

  • Other Parameters

  • Documentation

  • Gadget Packaging

  • Gadget Installation

  • Logging

  • Tips

States and Actions

Gadgets can interact with browser requests or application events by utilizing two types of methods:

  • Status changes

  • Action handling

Gadget State

A gadget will often need to return different data at different times based on some internal state. If the returned state is null, the GadgetManager will simply call the regular getData method. However, if the returned state is [state], then GadgetManager will expect the GadgetInstance to have implemented a method called get[state]Data and will call that method instead.

State Change

States may be changed from within the gadget as a result of some internal logic via the setState method. (This could be in be placed in processRequest()). Or override the gadget's internal state for a particular request by using the NPState parameter along with the GI_ID parameter in the query string part of the request.

For example: .?NPState=YYY&GI_ID=3 in a request will cause the gadget manager to call the getYYYData method on the gadget with ID 3. The code would be as follows:


public void getYYYData(HttpServletRequest req, BufferedWriter out, Document domDocument)
{
// ...
}

Actions.  A gadget will often need to process several different kinds of requests and needs a separate method for each request rather than funneling everything through processRequest.

Separate handler method for each action.

void onXXXAction(HttpServletRequest) throws GadgetInstanceException, where XXX is the name of the action.

Register Action Handlers.  You can implement an action handler by doing the following:

implement the addActionListner method:
addActionListner(this, "XXX");

Each listener must have the appropriate onXXXAction method. It must also implement the handleAction method, which will be called by the portal instead of the processRequest method (already done in BaseGadgetInstance).

Actions in Request.  An action is specified in the request using the NPAction=XXX parameter, where XXX is the name of the action. For example:

.?NPAction=XXX&GI_ID=3 in a request will cause the GadgetManager to call the onXXXAction method on the gadget with ID 3.

If no action is specified, the portal will call the GadgetInstance's processRequest method.

Default getData() called after onXXXAction()

Other Parameters.  FULLPAGE=branding

Only one gadget is called, session/branding data is still available.

/nps/portal/[xml]fullpageservice?GI_IG=17 replaces FULLPAGE=branding in v1.5.

Stylesheet Example:


<form method="POST" action="{$Portal.Servlet.FullPage}">
<input type="hidden" name="GI_ID" value="{GI_ID}"/>

Portal.Servlet.Fullpage is defined in LayoutSettings.xsl

CUSTOM_CONTENT_TYPE=y

Gadget gets full control

/nps/portal/customcontentservice?GI_ID=17 replaces CUSTOM_CONTENT_TYPE in v1.5

Stylesheet Example:


<form method="POST" action={$Portal.Servlet.CustomContent}">
<input type="hidden" name="GI_ID" value="{GI_ID}"/>

Portal.Servlet.CustomContent is defined in LayoutSettings.xsl

NPS SDK Documentation.  The NPS Documentation is available at http://www.developer.novell.com as a part of the NPS SDK. It includes documentation for the following classes for Gadgets to use:

  • AuthenticationManager

  • ConfigManager

  • PortalConnection

  • NPSMacroParser

  • XMLUtil

  • Debug

It also documents available interfaces for Gadgets:

  • AuthenticationEventListener

  • Configurable

  • Shortcutable

Gadget Packaging.  Gadgets are installed as packages (.npg files) in the <webapps>/nps/packages/ directory on Tomcat. Run java packaging utility or use the command line utility to do it. (.npg files can be viewed with WinZip. To package a Gadget using the Gadget Packager, run Packager.bat. This will bring up the following screen, Figure 33.

Gadget Packager.

Figure 33: Gadget Packager.

You will need to enter the Gadget name and the main gadget class. Click Next.

The next screen, Figure 34, allows you to select the class files used by the gadget.

Class File Section for Gadget.

Figure 34: Class File Section for Gadget.

Select the appropriate classes. Click Next.

The last screen, Figure 35, allows you to select the stylesheet directory for this gadget.

Selection of Stylesheet Directory for Gadget.

Figure 35: Selection of Stylesheet Directory for Gadget.

When completed selecting, click Finish to create the Gadget Package.

Installing the Packaged Gadget

When installed, the package deploys to the following directories in Tomcat:

  • Class files: <webapps>/nps/web-inf/classes/

  • Stylesheets: <webapps>/nps/portal/gadgets/

Incremental changes are made via overwriting the files in the above locations.

To install the gadget, follow these steps:

  1. Login to Portal as Admin

  2. Choose Portal Administration

  3. Click Install A Gadget

  4. Enter a name for the gadget. For example, cn=mygadget,o=novell

  5. Browse for Gadget Package. For example: getHTMLPage.npg

Previous Contents Next
download sample file