Customizing JBoss Portal

From ThemesWiki

Jump to: navigation, search
Customizing JBoss Portal
Official Page
Project Documentation
Download
Source Book
200px-1847194109.jpg
ISBN 978-1-847194-10-7
Publisher Packt Publishing
Author(s) Ramanujam Rao

Contents

[edit] Customizing the portal

There are many ways to customize portal pages, portlets, and content. The salient ones are setting preferences, drag-drop component repositioning, and changing the physical attributes of a page, such as font sizes, colors, and so on.

[edit] Setting preferences

Preferences allow the user of a portal to save information about a personal set of choices so that the portal output is customized for them every time they interact with the portal. Customization can either be in behavior, or in the output. An example of customized behavior is using Google Finance for retrieving stock information. An example of output customization is the number of FAQs displayed on a single page for a given topic.

The portlet specification provides options for setting preferences on the server. These can be overridden by the user. Let us take out example MyCompany portal application, and add some default preferences to the ContentPortlet. The following snippet of code from the portlet.xml portal deployment descriptor illustrates the setting of default preferences on the server. When the portlet is first deployed, or in scenarios when there is no user currently logged on, preferences are set by adding a new <portlet-preferences> section for each portlet definition.

<portlet>

<portlet-name>ContentPortlet</portlet-name>

<portlet-class> org.mycompany.portlet.content.ContentPortlet </portlet-class>

<supports>

<mime-type>text/html</mime-type>

<portlet-mode>VIEW</portlet-mode>

</supports>

<portlet-info>

<title>MyCompany Content Portlet</title>

</portlet-info>

<! - Portlet Preferences -->

<portlet-preferences>

<!-- Output Preference -->

<preference>

<name>color</name>

<value>Magenta</value>

</preference>

<preference>

<name>shape</name>

<value>Spiral</value>

</preference>

<preference>

<name>size</name>

<value>large</value>

<read-only>true</read-only>

</preference>

</portlet-preferences>

</portlet>

The rights to update and overwrite preferences are managed through personalization policies defined on the server. The portlet has three preferences that are defined, along with their default values. In the example above, we can also see a preference with the tag <read-only>true</read-only>. This indicates that the preference cannot be changed and it is only for reading. For editable preferences, portlets can change the value preference attributes by using the setValue, setValues, and reset methods of the PortletPreferences interface.

The ContentPortlet will provide a default set of preferences, and we will then allow the user to personalize the page by defining a new set of preferences.

Now that we have the default values defined, let's edit the portlet class to allow the setting of preferences by the user. The PortalPreferences class is responsible for storing and retrieving preference information. However, all invocations to PortalPreferences should only be in the processAction method.

Hence, our new processAction method looks like this:

public void processAction (ActionRequest request, ActionResponse actionResponse)

throws PortletException, java.io.IOException {

PortletPreferences pref = request.getPreferences();

pref.setValue("color",request.getParameter("color"));

pref.setValue("shape",request.getParameter("shape"));

pref.store();

actionResponse.setPortletMode(PortletMode.VIEW);

actionResponse.setRenderParameters(request.getParameterMap());

}

The rest of the methods remain the same. Once deployed, the application now shows the default preferences when there is either no user logged in, or the user has not selected any preference.

The user can then edit their preferences, which will be saved in their portal preference data.


The next time the user loads the page, it will be customized with the values that the user has defined. These values are retained even after the user logs off and logs back in again.


Although this example is very simple, it is meant to explain a very important aspect of the portal server. Because the server retains user choices and preferences between multiple sessions, we can develop portal applications that look up these preference values and customize the page accordingly. It is also important to note that the portal server has managed all of the details of capturing, retaining, and co-relating the preference information, without the developer having to deal with databases and code.

[edit] Internationalization and localization

Internationalization (I18N) and Localization (L10N) are fairly common requirements in portals. They are primarily used to customize content as per the locale and language specified in the user's preferences. They can also be used to customize number, date and time formats, and to provide messages in the user's preferred language.

The portlet deployment descriptor allows for localization at deploy and run times. The deploy time values are the ones that are used when a given portlet is deployed. The runtime option is the definition of a set of supported localized language alternatives.

In the deployment descriptor, the default value is English, en, although more languages can also be declared. The following example illustrates the deploy and runtime declaration of locales:

<portlet-app>

<description xml:lang="en">

Portlet displaying the time in different time zones

</description>

<description xml:lang="de">

Dieses Portlet zeigt die Zeit in verschiedenen Zeitzonen an.

</description>

<portlet-name>TimeZoneClock</portlet-name>

<display-name xml:lang="en"> Time Zone Clock Portlet </display-name>

<display-name xml:lang="de"> ZeitzonenPortlet </display-name>

<portlet-class>

com.myco.samplets.util.zoneclock.ZoneClock

</portlet-class>

<expiration-cache>60</expiration-cache>

<supports>

<mime-type>text/html</mime-type>

<portlet-mode>config</portlet-mode>

<portlet-mode>edit</portlet-mode>

<portlet-mode>help</portlet-mode>

</supports>

<supported-locale>en</supported-locale>

<supported-locale>fr</supported-locale>

</portlet-app>

The <supported-locale> tag lists the available run-time customization options for locale.

[edit] Drag-and-drop content

This is a feature that allows users to drag-and-drop various portlet windows within a page. The option is set as a configurable parameter on the server. Once set, the user will have options available on the screen to perform dynamic and rich user interface functions such as dragging windows, repositioning portlets on a page, and so on. However, this feature is most applicable on pages that have multiple windows. There is not much use for dynamic repositioning of windows on pages that have a very small set of information blocks and only have a lot of empty space to move around. As a dashboard typically consists of multiple windows that fill the page, feature is only available on a dashboard.

The following is a brief snippet of code that sets the flag that will allow the drag-and-drop of portlet windows:

<deployment>

<parent-ref />

<if-exists>keep</if-exists>

<context>

<context-name>dashboard</context-name>

<properties>

...

<property>

<name>theme.dyna.dnd_enabled</name>

<value>true</value>

</property>

...

</properties>

...

</context>

</deployment>

By setting the value of the parameter theme.dyna.dnd_enabled to true, we have now set the dashboard page to have drag-and-drop features. The user can now customize the screen by dragging and dropping elements within the page.

[edit] Usability settings

Usability settings include using portlets for temporary functions, manipulating the state of the portlets for transient use during the session, and so on.

For example, some users like to use a portlet, such as a stock quote portlet, to get the values that are used only during their current session. They don't care about saving them. Similarly, somebody might decide to minimize or close some portlets and create more room on the page to better facilitate the task they are there for. The portal server supports features like these through its window renderers, and allows a user to configure a page that best fits their needs.

The transient information is managed by the portal using the PortletSession interface.

The following is a small snippet of code that illustrates how information is added to and retrieved from the portal session. These sessions are tied to the users and the browsers that they are using. As soon as the user logs out, or closes the browser, the session expires, and so does all of the data that we stored in it during the user's interaction with the portal.

public void processAction(ActionRequest request, ActionResponse response)

throws PortletException, IOException

{

...

if (request.equals("appendPlaylist"))

{

PortletSession pSession = request.getPortletSession();

PlaylList list = (PortletSession)session. getAttribute("playlist");

list.addSong(song);

// We need to now add the updated playlist to the session

session.setAttribute("playlist", list);

}

...

}

[edit] Additional References

  • For instructions on Installing JBoss Portal, click here
  • For instructions on Installing JBoss Tools, click here
  • For instructions on Set Up for JBoss Drools, click here

[edit] Source

The source of this content is Chapter 5: Customizing JBoss Portal of JBoss Portal Server Development by Ramanujam Rao (Packt Publishing, 2009).logo design by Kevin Josh 2010

Executive Editor Sean Lopez own  : SEO Company and provider of Link Building Services and SEO Services

And Like Costumes and Halloween Costumes and criar sites

And Like The Global Information Network and Global Information Network

Personal tools