Editing Preferences

Editing Preferences is functionality available on many portlets in "my groundwork" tab. user can edit enter choices and select options to customize portlet according to needs.

JSP page

These pages are generally suffixed with "XXXpref.jsp" and are simple JSP pages. Many pages use JQuery libraries like auto complete to achieve dynamic functionality. We need to include <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> This tag lib in page and use <form method="post" action="<portlet:actionURL/>"></form> tag to accommodate all the editing UI code inside it. 

sample page:
<%@ page language="java"%>
<%@ page import="javax.portlet.RenderRequest"%>
<%@ page import="javax.portlet.RenderResponse"%>
<%@ page import="com.groundworkopensource.portal.statusviewer.handler.ReferenceTreeMetaModel"%>
<jsp:useBean id="referenceTree" scope="application"
	class="com.groundworkopensource.portal.statusviewer.handler.ReferenceTreeMetaModel" />
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
<form method="post" action="<portlet:actionURL/>">
<table border="0">
	<tr>
		<td>Enter Host Name :</td>
		<td><input type="text" name='hostPref' id='hostPref'
			value='<%=renderRequest.getAttribute("hostPref")%>' /></td>
	</tr>

	<tr>
		<td>Enter Custom Portlet Title :</td>
		<td><input type="text" id='customPortletTitle' name='customPortletTitle'
			value='<%=renderRequest.getAttribute("customPortletTitle")%>' /></td>
	</tr>

	<tr>
		<td colspan="2"><input type="submit" id='savePrefs' value="Save Preferences"></td>
	</tr>
</table>

</form>

renderRequest.getAttribute("customPortletTitle") is used to show previous values of that fields on page.

Portlet class

When user click on "edit preferences" icon, doEdit() method of portlet class gets called. We actually call "request.setAttribute()" method in Baseportlet.java class and set required attributes in portlet request. Hence we need to provide appropriate parameters to "doEditPref()" method of Baseportlet.

When user saves preferences, we call "processAction()" method of portlet class. In this method, we call base class method of same name and actually save those preferences by using "PortletPreferences.store()" method. So we need to send appropriate parameters to this method.

Changes needs to be done in several "maps" that we are using to store actual preferences keys. At some places we are using "EditPrefsBean" class to Carrie those values.

Database

Preferences are stored in jboss-portal database.

Accessing preferences and specifying in XML file

Preferences are generally accessed with several methods available in FacesUtils class like getPreference(String key). We can also specify some preferences and there default values in portlet.xml file in code, by using portlet-preferences tag.

Example:
<portlet-preferences>
	<preference>
		<name>defaultServicePref</name>
		<value>icmp_ping</value>
	</preference>
</portlet-preferences>
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.