Post details: Setting a portlet title in a JSF webapp

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;
	}

}

Comments, Pingbacks:

Comment from: Faisal Taimoor [Visitor] · http://ftaimoor.multiply.com
This is nice chunk of code but where does phase listner fit in the portlet application ?
Permalink 04/04/07 @ 17:15
Comment from: Dave Brondsema [Member] · http://brondsema.net/
You don't have to do anything else to make it hook into the portlet lifecycle. As long as JSF is properly configured for the portlet app, it will invoke this listener.
Permalink 04/05/07 @ 13:10

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.
What is the 2-letter abbreviation for Michigan?
Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)

<  June 2019  >
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