Archives for: April 2006, 25

Apr 25, 2006 : Setting a portlet title in a JSF webapp

Here's how you can set a portlet title in a JSF webapp. This uses the "title" preference to define what the portlet title is, but you could easily code it to get the title in other ways.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC
  "-Sun Microsystems, Inc.DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
	...
	<lifecycle>
		<phase-listener>edu.cornerstone.jsf.util.PortletTitlePhaseListener</phase-listener>
	</lifecycle>
	...
package edu.cornerstone.jsf.util;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.portlet.PortletRequest;
import javax.portlet.RenderResponse;

public class PortletTitlePhaseListener implements PhaseListener {

	public void afterPhase(PhaseEvent event) {

	}

	public void beforePhase(PhaseEvent event) {
		RenderResponse response = (RenderResponse) event.getFacesContext()
				.getExternalContext().getResponse();
		PortletRequest request = (PortletRequest) event.getFacesContext()
				.getExternalContext().getRequest();
		String title = request.getPreferences().getValue("title", null);
		if (title != null) {
			response.setTitle(title);
		}
	}

	public PhaseId getPhaseId() {
		return PhaseId.RENDER_RESPONSE;
	}

}

<  April 2006  >
Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Categories


Archives

Misc

Syndicate this blog XML

powered by
b2evolution