Advanced Gadget Development In this section, we will cover advanced topics of Gadget Development. Some of the areas covered will be:
States and Actions Gadgets can interact with browser requests or application events by utilizing two types of methods:
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: 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}">
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}">
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:
It also documents available interfaces for Gadgets:
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.
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.
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.
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:
Incremental changes are made via overwriting the files in the above locations. To install the gadget, follow these steps:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||