2. Standard Portlet Examples

This section shows some examples of portlets, that strictly follow the portlet standards JSR 168: Portlet Specification and JSR 286: Portlet Specification 2.0 .

2.1. Hello World

This chapter covers a simple HelloWorld portlet example. Look for the HelloWorld.java class in the example sources of your SamplePortletapplication. All other examples are stored in your SamplePortletapplication. It simply writes text into the response. If you want to create your own new HelloWorld Portlet, follow these steps or use the appropriate eclipse cheat sheet. 
Launch HelloWorld cheat sheet.
Launch HelloWorld cheat sheet. You can also find an existing HelloWorld portlet within the Gentics Portal.Node SDK Portal.


Show example in
Gentics Portal.Node SDK
Show example in Gentics Portal.Node SDK

  1. Create a new class MyHelloWorld next to the existing HelloWorld.java which will extend GenericPortlet .

  2. Implement the method doView() . This is the method that will be called by Gentics Portal.Node in order to let the portlet render its content in the default windowstate view.

  3. Instantiate a writer using the method getWriter() from the renderResponse object and print any line you want: renderResponse.getWriter().println("my first portlet!");

  4. Register the module in the Portlet-Descriptor file portlet.xml

    Example 4.1. Hello World XML

    <portlet>
      <portlet-name>myHelloWorld</portlet-name>
      <portlet-info>HelloWorld</portlet-info>
      <portlet-class>com.gentics.portalnode.sdk.myHelloWorld</portlet-class>
      <supports>
        <mime-type>text/html</mime-type>
      </supports>
    </portlet>
    			
  5. Place the portlet somewhere in the portlet entities file portletentities.xml, eg. above the existing HelloWorld:

    Example 4.2. HelloWorld pnode

    <pnode type="myHelloWorld" id="myHello">
    <style>default</style>
    </pnode>
    					
  6. Place the portlet entity in at least one portal page in the portal configuration file default.portal.xml in the pages-section .

  7. Restart sdk portal server and take a look at the new portal.

2.2. Resource Serving Example

This simple example demonstrates how JSR 286 Resource Serving can be used.

The ServeResourceExample Portlet, once placed inside a Portal Page will output textual content with special css styling applied. Thus the browser would render white text upon white background which cannot be read by the user, followed by a red warning text. Incorporating the portlet's serveResource() method (q.e.d.) a simple stylesheet is applied, which turns the white text to readable black, and hides the red warning text. So if you are able to read the black text when displaying the portlet, everything went smooth, and the resource (the stylesheet file in our case) was served properly.


Show example in
Gentics Portal.Node SDK
Show example in Gentics Portal.Node SDK

2.3. Events Example

This is a simple example, demonstrating how the event handling works according to the JSR 286 specification.

The example consists of two portlets:

In the deployment descriptor WEB-INF/portlet.xml , the event has to be defined as <event-definition> along with the definition, which portlets support sending ( <supported-publishing-event> ) and which support receiving ( <supported-processing-event> ) the event. 
Show deployment descriptor
Show deployment descriptor

When you maximize the EventReceiverPortlet, such that the portlet is rendered twice in the page, you will notice that for every click on the event sender action URL, the counter in the EventReceiverPortlet is incremented by two. This is because the portlet receives the event for every visible instance (on every page).

2.4. 3rd Party Portlet

Covers integration of existing 3rd party portlets.

Copy the class files of the 3rd party portlets into WEB-INF/classes and eventually needed libraries into WEB-INF/lib . Typically, portlets will be delivered with additional web files (like images, jsp files, html files, etc.). Copy all those files into the root folder of the project which serves also as web folder of the application. Insert the content of the portlets’ Portlet-Descriptor into the general Portlet-Descriptor file. Place the module into the portaltemplate sample.portaltemplate.xml Restart SDK Portal Server.

There are two 3rd party portlets already integrated with the SDK, the Bookmarks portlet and the Nodepad portlet. Both are selfexplaining, just view them in portletmode help to get a short description.


Show BookmarkPortlet in
Gentics Portal.Node SDK
Show BookmarkPortlet in Gentics Portal.Node SDK


Show NotePadPortlet in
Gentics Portal.Node SDK
Show NotePadPortlet in Gentics Portal.Node SDK