Reading Portlet Preferences in Weblogic Portal
| Posted by watashii | Filed under Programming, WebPortlet preferences enables portlets to be associated with external application data. This data should generally be used to store (or update) configuration data in a portlet. For example, to store/update dynamic stock codes in a stock quotes portlet. A portlet preference is basically a name-value pair data structure.
Portlet preferences can be added/updated in the following ways:
- During design-time on Workshop for Weblogic Portal (screenshot above)
- Invoked programmatically at request-time using javax.portlet.* API
- Manually during run-time of a portal (via Portal Administration Console when a portal desktop is created)
When we have added our preferences, we can read them using using the Weblogic Portal API’s. The following sample code fragments are for JSP Portlets, and JSF Portlets:
JSP Portlets using JSP tag library:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/netuix/preferences" prefix="preferences" %>
<preferences:getPreference name="stockcode" var="mycode"/>
<c:out value="${mycode}"/>
JSF Portlets using Preferences API (in backing bean):
FacesContext fc = FacesContext.getCurrentInstance();
PortletRequest portletRequest = (PortletRequest)fc.getExternalContext().getRequest();
PortletPreferences prefs = portletRequest.getPreferences();
System.out.println(prefs.getValue("stockcode", "default_value_if_pref_not_found"));
Related Posts:
- Weblogic Portal – Create Streaming Desktop Page Definition Error
- Using JSF 1.2 on Oracle Workshop for Weblogic (Portal 10.3)
- Weblogic Portal Authorization – Get and Check User’s Roles
- Encrypt Passwords With Weblogic Server
- Start & Stop Weblogic Without Username & Password
Tags: java, jsp, portal, portlets, preferences, weblogic
