This section shows some examples of portlets, that strictly follow the portlet standards JSR 168: Portlet Specification and JSR 286: Portlet Specification 2.0 .
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.
You can also find an existing HelloWorld portlet within
the Gentics Portal.Node SDK Portal.
Show example in
Gentics Portal.Node SDK
Create a new class
MyHelloWorld
next to the existing
HelloWorld.java
which will extend
GenericPortlet
.
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
.
Instantiate a writer using the method
getWriter()
from the renderResponse object and print any
line you want:
renderResponse.getWriter().println("my first
portlet!");
Register the module in the Portlet-Descriptor
file portlet.xml
Place the portlet somewhere in the
portlet entities file portletentities.xml
, eg. above the existing
HelloWorld:
Place the portlet entity in at least one portal
page in the portal configuration file
default.portal.xml
in the
pages-section
.
Restart sdk portal server and take a look at the new portal.
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.
This is a simple example, demonstrating how the event handling works according to the JSR 286 specification.
The example consists of two portlets:
EventSenderPortlet
which sends the event (every time the action
URL is triggered).
EventReceiverPortlet
which counts, how many times the event was
caught.
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
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).
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.