Novell is now a part of Micro Focus

How a Gadget Works

Articles and Tips: tip

Kevin Burnett
Senior Research Engineer
Novell, Inc.
kburnett@novell.com

01 May 2003


The following is from the new Novell Portal Services Overview and Gadget Development course. All DeveloperNet University (DNU) courses are available at http://developer.novell.com/education/

When a user first brings up a portal page in a browser, the portal creates a new instance of each gadget on that page and assigns it a unique ID. The gadget instance maintains state information about that user's session, which continues to exist until the servlet engine drops the session. The portal then calls the init(String[] args) method of each gadget.

Gadgets that Use XSLT Style Sheets

For gadgets that use XSLT style sheets to generate their interface, after the portal initializes the gadget, the portal calls the getData and getStylesheetAndResourceSets methods of the gadget instance to get the XML data and the XSLT style sheet URL. The portal renders the gadget display by using the style sheet to transform the XML data into HTML or some other format. Whenever the portal needs to regenerate the display, it again calls these two methods of this same gadget instance.

To see an example of how this works lets look at a section of the HelloWorld.java file download from the course at http://www.developer.novell.com/education/.

If you look at the getData method, you will notice that the method returns the following three lines to the portal (using convenience methods of the com.novell.nps.gadgetManager.XmlUtil class):

<HelloWorld>
    <HELLODATA>Hello World!</HELLODATA>
    </HelloWorld>

The portal receives this XML data, then applies the HelloWorld style sheet. Since HelloWorld does not override getStylesheetAndResourceSets, the portal loads the default style sheet specified in com.novell.nps.gadgetManager.BaseGadgetInstance, which is main.xsl. This XSL style sheet uses only three lines to format the data:

<xsl:template match="HelloWorld">
<xsl:value-of select='HELLODATA'/>
</xsl:template>

The portal replaces <xsl:value-of select='HELLODATA'/> with the data in the HELLODATA tags, Hello World!, according to XSLT rules, and displays the data in the portal.

Gadgets that Use JSPs

For gadgets that use JSPs (Java Server Pages), the portal calls the execute(HttpServletRequest req) method of the gadget, which sets the initial JSP by calling setModuleStylesheet(String moduleStylesheet). The gadget also stores data in a java.util.Properties object called m_JSPDataObject.

The portal uses this initial JSP and the data stored in m_JSPDataObject to render the initial user interface for the gadget. If the user interface must change, such as in response to user interaction, other JSPs are required for each UI change.

The JSP is a file on the iManager server that operates as a template for the gadget user interface. It contains dynamic code enclosed in special tags interspersed with static HTML markup. The dynamic portions can cause variable data to be inserted, such as data from m_JSPDataObject. They can also insert the results of other processing.

Installing the Gadget Runner

The Novell Gadget Developer Kit (GDK) is available on Novell's Developer Web Page (http://www.developer.novell.com) and contains a tool called the Gadget Runner. This tool is optional for this course, but may make your life easier in completing the labs at the end of this course. If you opt to use the Gadget Runner, make sure you have downloaded the GDK, and follow the instructions.

Using the Gadget Runner

This section shows you how to use the Gadget Runner that is bundled with the GDK. The Gadget Runner is a customized version of the Tomcat 4.x servlet container that runs a developer version of Novell exteNd Director, Standard Edition.

The Gadget Runner displays a single gadget at a time on your development workstation, allowing you to easily develop and test gadgets before loading them on a Novell exteNd Director server. The Gadget Runner is compatible with the dynamic class loading feature of Tomcat 4, which allows you to change your gadget code, recompile, and test your changes without restarting the Gadget Runner.

The Gadget Runner is installed with the Gadget Development Kit (GDK). To run your gadgets in the Gadget Runner:

  1. Copy your style sheets to the GDK_HOME\tomcat\webapps\nps\portal\gadgets\gadgetclassname\skins\default\devices\default folder, where GDK_HOME represents the directory where you installed the GDK files and gadgetclassname represents the fully-qualified name the main class of your gadget.

  2. Copy the compiled class files of the gadget to the directory GDK_HOME\tomcat\webapps\nps\WEB-INF\classes. If you have archived your gadget in a JAR file, copy it to the GDK_HOME\tomcat\webapps\nps\WEB-INF\lib directory.

  3. Run GDK_HOME\gadgetRunner.bat to start the Gadget Runner.

  4. The Gadget Runner executes in a separate window, where a number of status messages appear during initialization. When the Gadget Runner is running, open your Web browser and browse to http://localhost:8080/nps/index.html . You know the Gadget Runner is running when you see a message similar to the following:

    INFO: Jk running ID=0 time=16/78 config=C:\gdk\.\tomcat\conf\jk2.properties
  5. Select the gadget you want to run from the drop-down list and click the Run button.

  6. To stop the Gadget Runner, execute GDK_HOME\tomcat\bin\shutdown.bat.

You might also be able to start the Gadget Runner from within your IDE (integrated development environment), but this depends on the type of IDE you are using. See Setting Up a Development Environment, in the GDK in the actual course for more information.

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Micro Focus