Example portlets

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

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.zipZIP (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.

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.zipZIP (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)

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.zipZIP (zip, 4.3 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.rarrar file (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.

Denna sida publicerades: 2017-05-15

Skriv ut PDF-avsnitt

Hjälpte informationen på den här sidan dig?

Missa inga nya rön, tips och tricks! Prenumerera på insite!

Find us!

SiteVision AB (Headquarter)
Vasagatan 10
702 10 Orebro
Sweden

Info: +46 19-17 30 30
Support: +46 19-17 30 39

Latest Tweets