Last week, I had to simulate a "subscribe/unsubscribe" mechanism for WebLogic Portal (WLP) 10.3. The basic
idea is that the user has an option to subscribe to a portlet, from a list of available portlets, and that is displayed
in his main page.
After some research, I found some good reference from
Balz
Schreier on the WLP Portlet Preferences APIs. In his example, Balz shows how to get access to
PortalCustomizationManager which allows us to perform various
operations, including removing -
.removePlaceable - and adding -
.addPlaceable - portlets
to a Page.
Using similar code, we could also get access to
PortletDefinitionManager , which will give us access to all
portlets for the Web Application -
.getPublicPortletDefinitions.
In my example, the idea is to "replace" the existing portlet subscription with a new one. To
simplify things in my example, I have 2 portlets - weather & stocks - and user can either view one or the other. So,
when it is time to change the subscription, I just look for the one that is currently showing -
_oldPlaceableView
-, so I can get its
PlaceholderDefinitionId &
PlaceHolderPosition. This is needed, as the new portlet
-
_newPortletDef - will show up in the same location.
Now, we have all the APIs to:
- getPortalCustomizationManager -- return instance of PortalCustomizationManager.
- getPortletDefinitionManager -- return instance of PortletDefinitionManager.
- getAllPortlets -- returns a list of all available portlets for the Web Application.
- findPortlet -- finds the PortletDefinition for the new portlet to be subscribed to.
- findPlaceableView -- finds the PlaceableView instance of the current portlet.
- deleteCustomizations -- helper to clean up all the customizations for this user, and reset the original
state of the page. Useful for the testing, where things start getting messy after some time, and you want to clean it
all up. I received this code from an Oracle peer.
- subscribePortlet -- wraps all the calls into a single method, to make it easier for the test JSP page.
It is also important to say that the user must be authenticated for this to work the way we wanted. In my test.jsp, I
have a reference to an
authenticate
method, that simply calls
com.bea.p13n.security.Authentication.login.
Putting it all together, here is
WlpHelper.java and
test.jsp. The idea is to start with a simple JSP just to validate the flow, but that later could
turn into a "Preferences Page" of some sort, where user views all the available portlets and can choose which
one to subscribe to.
Here is the original page, showing the Stocks portlet:
and this is after executing the
test.jsp with the following parameters:
http://localhost:7001/tutorial_portalWeb/test.jsp?username=rolima&password=welcome1&action=subWeather
The example is really simple, but the starting APIs are there for you build from it.
Have fun!