Changing title of portal page

The JSR 286 specification has a concept of two phase rendering, you can use it to add element in the portal document's head section, one use case for doing that would be if you want to change the title of the portal page.

I wanted to try that so i created this TwoPhaseRenderingPortlet.java like this

package com.ibm.webspherenotes.jsr286;

import java.io.IOException;

import javax.portlet.GenericPortlet;
import javax.portlet.MimeResponse;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.w3c.dom.Element;

public class TwoPhaseRenderingPortlet extends GenericPortlet{
protected void doHeaders(RenderRequest request, RenderResponse response) {
System.out.println("Entering TwoPhaseRenderingPortlet.doHeaders()");

Element title = response.createElement("title");
title.setTextContent("www.webspherenotes.com portal page");
response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, title);

System.out.println("Exiting TwoPhaseRenderingPortlet.doHeaders()");
}
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering TwoPhaseRenderingPortlet.doView()");
response.setContentType("text/html");
response.getWriter().println("Hello from two phase rendering portlet");
System.out.println("Exiting TwoPhaseRenderingPortlet.doView()");
}
}


In the TwoPhaseRenderingPortlet, i am overriding doHeaders() method and inside the method, first i am creating a title element then i am setting the value of that element to www.webspherenotes.com portal page and the last step is to call response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, title); method which asks the RenderReponse object to insert newly created title element in the head section of the document.

Once the portlet is deployed i tried accessing it and i can see that the title that i set is displayed in the title bar of the browser, also when i tried looking at the source code i could see that the <title> element is added

5 comments:

  1. Does the tow-phase rendering is supported in WP 6.1.5? I dont see such a comment in the infocenter, but it does not work for me. Can someone confirm this?

    ReplyDelete
  2. That's great I've been looking for this king of functionality for a while.

    Now quick the question:

    Does the 286 implementation of WCM leverage such functionality in ordert to allow me to set that title too?

    ReplyDelete
  3. Didn't work for me :(
    I'm using Websphere Portal 6.1.

    ReplyDelete