Creating portal pages on the fly

WebSphere Portal has concept of DynamicUIManagementFactoryService that you can use to create portal pages on the fly, add portlets to the pages,..etc. The pages that you create or portlets that you add with this method are available only in the current user session, so once user logs off these changes would be lost.

I followed the instructions in Exploiting the WebSphere Portal programming model: Part 4: Making your portal dynamic and context sensitive article to create a sample portlet that will create a dynamic page and then display that page in dialog box. THis is how my sample portlet looks like

package com.webspherenotes.portlet;


import javax.naming.CompositeName;
import javax.naming.InitialContext;
import javax.naming.InvalidNameException;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;


public class DynamicUIPortlet extends GenericPortlet {

public static final String EXTENSION_PAGE_UNIQUENAME="com.webspherenotes.popup.extension";
public static final String TEMPLATE_PAGE_UNIQUENAME="com.webspherenotes.popup.dynamic";

public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
System.out.println("Entering DynamicUIPortlet.processAction()");

try {
RedirectURLGenerator redirectURLGenerator = redirectURLGeneratorService.getURLGenerator(request, response);

DynamicUICtrl dynamicUIControl= dynamicUIManagerFactoryService.getDynamicUICtrl(request, response, EXTENSION_PAGE_UNIQUENAME);

ObjectID templatePageObjectId = getObjectID(TEMPLATE_PAGE_UNIQUENAME);
System.out.println("Template Page Object Id " + templatePageObjectId);
ObjectID dynamicPageObjectId = dynamicUIControl.addPage(templatePageObjectId, new LocalizedImpl("Dynamic page", "Dynamic page demo"), null);

System.out.println("Lauch page object id " + dynamicPageObjectId);

EngineURL dynamicPageURL = redirectURLGenerator.createPageURL(dynamicPageObjectId);
String dynamicPageURLStr = dynamicPageURL.toString();

System.out.println("Dynamic Page URL " + dynamicPageURLStr);
} catch (DynamicUIManagementException e) {
} catch (StateException e) {
System.out.println("Exiting DynamicUIPortlet.processAction()");

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering DynamicUIPortlet.doView()");
getPortletContext().getRequestDispatcher("/index.jsp").include(request, response);
System.out.println("Exiting DynamicUIPortlet.doView()");

RedirectURLGeneratorFactoryService redirectURLGeneratorService;
DynamicUIManagementFactoryService dynamicUIManagerFactoryService;

public void init() throws PortletException {
System.out.println("ENtering DynamicUIPortlet.init()");
try {
InitialContext ctx = new InitialContext();
final PortletServiceHome dynamicUIManagerFactoryServiceHome = (PortletServiceHome) ctx
dynamicUIManagerFactoryService = (DynamicUIManagementFactoryService) dynamicUIManagerFactoryServiceHome

final PortletServiceHome redirectServiceHome = (PortletServiceHome) ctx
redirectURLGeneratorService = (RedirectURLGeneratorFactoryService) redirectServiceHome
} catch (NamingException e) {
System.out.println("Exiting DynamicUIPortlet.init()");

private ObjectID getObjectID(String uniqueNameStr) {
try {
InitialContext ctx = new InitialContext();
final Name uniqueName = new CompositeName("portal:uniquename");
ObjectID oidForUniqueName = (ObjectID) ctx.lookup(uniqueName);
return oidForUniqueName;
} catch (InvalidNameException e) {
} catch (NamingException e) {
return null;

In the doView() method of the DynamicUIPortlet, i am forwarding control to index.jsp page, which looks like this

<%@page language="java" contentType="text/html; %>
<%@taglib uri="" prefix="portlet"%>
<%@ taglib uri="" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/portal.tld" prefix="portal" %>

<portlet:defineObjects />

<script type="text/javascript">
function openPopup(popupUrl){
if (window.showModalDialog) {
} else {,'name',
resizable=no ,modal=yes');

<input type="button" onclick="openPopup('<portlet:actionURL/>')" value="Dynamic Page" />

When you click on the DYnamic Page button it creates a actionURL and opens it in the dialog box.

The DynamicUIService has restriction that you can call it only during the action phase of the portlet, so inside the processAction() method i am calling dynamicUIControl.addPage() method to add a dynamic page and then create redirectURL to the newly created page by calling redirectURLGenerator.createPageURL() method and then redirecting it to that URL. This is the UI that i get when i click on the Dynamic Page button


Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

srjwebsolutions said...

We are leading responsive website designing and development company in Noida.
We are offering mobile friendly responsive website designing, website development, e-commerce website, seo service and sem services in Noida.

Responsive Website Designing Company in Noida
Website Designing Company in Noida
SEO Services in Noida
SMO Services in Noida

EG MEDI said... is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online.
Cash on Delivery available. Free Home Delivery

Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store