So far, we have discussed portals and how to create pages. Now, you are ready to learn how to use portlets.
A Portlet is an application that contains specific business logic that provides a fragment of content in a portal page. The information shown as the output of a portlet could depend on specific user permissions. Permissions are related to the user accessing the page; this means that the potential output for the fragment is dynamic for each user.
Each portlet is hosted in a Portlet Container that manages the execution of portlet requests and provides a user-session mechanism. The sessions are used to check permissions and to show user-oriented information for each active session in the portal.
In this example, you will learn how to add and remove applications against portal pages.
We want to create a standard portlet for showing details in the Contact us page that we have created in the previous recipe.
In this recipe, we will start by implementing a portlet as a Gadget without writing specific Java code.
A Gadget is a simple application written in XML and JavaScript that allows you to create custom dashboards for specific user-oriented features that can be used by any gadget container.
First, let's create a new gadget showing the HTML content for our new Contact us page:
Contactus
in the Name field and type the following code in the Source field:<?xml version="1.0" encoding="UTF-8" ?> <!-- ** * * Author : Piergiorgio Lucidi * * Apr 06, 2012 * --> <Module> <ModulePrefs author="Piergiorgio Lucidi" title="Contact us" directory_title="Contact us" title_url="http://www.open4dev.com" description="This is the Contact us page of the example Financials portal." height="600"> <Locale lang="en"/> </ModulePrefs> <Content type="html"> <![CDATA[ <body> <div> <h2>Your company name</h2> <strong>Our Office</strong> <p>Your company address</p> <p>Your company phone number</p> <strong>Email us</strong> <p><a href="mailto:[email protected]">[email protected]</a></p> </div> </body> ]]> </Content> </Module>
GateIn supports standard portlets and standard gadgets as applications for pages.
In this recipe, we have seen how to create a new standard custom gadget to create an HTML fragment for a block in the page.
This is done because GateIn doesn't provide any mechanism for dynamic web content management, but you can implement your own portlet to achieve this goal for your specific requirements.
Notice that the Enterprise versions of GateIn, provided by JBoss and eXo, include specific types of portlets dedicated to managing web content.
The differences between portlets and gadgets are related to your specific requirements, and depend on the type of business logic that you need to implement.
A gadget is based on XML and JavaScript code, this means you can't write complex business logic rules for your client application. You can only implement a simple client application for rendering the HTML fragment for the page.
However, if you need an Enterprise-class code for your business logic and you need to write your own Java code, you have to implement a standard portlet for your client. In this way you will have all the capabilities offered by the portlet standard that are available in GateIn as a standard portlet container.
Of course, you can try to use other portlets in the Page Editor. The categories available in the Applications tab are as follows:
Under the Administration category, you will find the following portlets:
The Dashboard category contains the following:
The Gadget Wrapper Portlet is the default wrapper that is automatically applied when you drag-and-drop a gadget in the page. This is done because in any portlet container, you need a portlet implementation for each application and GateIn provides a standard wrapper for supporting gadget applications.
The default Gadgets provided in GateIn are:
Finally, the last category available is Web, which contains the following portlets:
iframe
tag configuring the src
attribute in the portlet preferencesUsing the Containers tab, you can add some sections in the page with a dedicated layout, with the following options:
By simply dragging-and-dropping portlets on the page, you can set up a different output for the page. For instance, we can now try to set up a three-columns layout and then add three different applications in the same row:
You should see output in your page similar to the following screenshot:
In this section, we will see how we can manage the settings for a portlet:
3.137.217.17