SiteVision Onlinehelp
Search

Example portlets

This page contains the source code for some example portlets that might help you getting started developing portlets.

Disclaimer! All examples here are for the 2.6/2.7 series of SiteVision. The code / implementation might have to be adjusted some for the SiteVision 3 series.

HelloWorldPortlet

This is a the mandatory Hello world example in portlet style (GenericPortlet).

The HelloWorld portlet demonstrates how to:

  • Write html output from a portlet
  • Use a JSR 168-defined css class (portlet-font)

The source code for the HelloWorld portlet is available for download as a zip here:
helloworld.zip Zip, 15.2 kB.

EditModePortlet

This is a sample (GenericPortlet) portlet that demonstrates how to use the PortletMode.EDIT that allows user-specific portlet preferences.

A note about SiteVision 2.4/2.5:

Versions prior to SiteVision 2.6 handled PortletMode.EDIT somewhat different. Deploying this portlet in SiteVision 2.5 will result in a behaviour that is similar to the behaviour of portlets that uses the SiteVision-specific config mode.

A note about SiteVision 2.6:

In SiteVision 2.6 and SiteVision 2.6_01 you must set a system property to break backward compatibility and enable proper EDIT mode processing (add "senselogic.portlet.enableuserprefs=true" in the System.properties file). In SiteVision 2.6_02 and later, no system property is needed since proper EDIT mode processing is enabled by default.

The EditMode portlet demonstrates how to:

  • Add the edit mode and default portlet preferences values in portlet.xml
  • Use the doEdit method and the processAction method to save user-specific preferences

The source code for the Editmode portlet is available for download as a zip here:
editmode.zip Zip, 93.7 kB.

ConfigModePortlet

This is a sample (GenericPortlet) portlet that demonstrates how to use the SiteVision-specific config PortletMode that allows update of the shared portlet preferences.

I.e. this portlet mimicks the behaviour of the build-in portlets bundled with SiteVision. A editor can double-click the portlet and edit the portlet settings, and this affects all users. (PortletMode.EDIT defined by JSR 168 is per user, SiteVisions config mode is per instance)

Note that this portlet uses methods in the SiteVision Utility API that are not available prior to SiteVision 2.6. Deploying this portlet in SiteVision 2.5 will result in undefined behaviour.

The ConfigMode portlet demonstrates how to:

  • Add the SiteVision-specific config mode in portlet.xml
  • Dispatch to the config mode
  • Use the SiteVision Utility API to ensure that only users with write permissions can use the config mode (i.e. update the shared portlet perferences).

The source code for the Configmode portlet is available for download as a zip here:
configmode.zip Zip, 95.1 kB.

NasdaqPortlet

This is a sample (GenericPortlet) portlet that displays information for certain Nasdaq stocks. In order to get stock information, the portlet consumes a Web Service available at http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2.

Note that the communication between the portlet and the web service doesn't use any Web Services framework. This portlet should only be seen as an example of a portlet that has some kind of business logic (i.e. calls a web service) - NOT an example of how to properly handle Web Services from a portlet!

The Nasdaq portlet demonstrates how to:

  • do a simple portlet without any MVC framework
  • separate between the action phase and the rendering phase
  • propagate result between the action phase and the rendering phase
  • dispatch the rendering to a JSP
  • use bundles to do the portlet i18n:ed (note: default and fallback locale for JSTL is specified in web.xml)
  • use JSTL and the portlet tag library in the JSP
  • use portlet preferences (illustrated by configuring a timeout and fonts in portlet.xml)
  • use commons logging for logging to the server.log of SiteVision

The source code for the Nasdaq portlet is available for download as a zipped rar here: webservices-example.rar Rar file, 874.7 kB.. More information about the portlet and how to build it can be found in the INFO file.

Struts 2 portlet

A generic Struts 2 portlet can be generated via Maven. You can find out more about this on the Struts 2 Portlet Tutorial.

Last updated:

se-sto-pio-sv5-2.sitevision-cloud.net
52.14.85.76