jQuery in Action, 3rd edition
The moose likes Portals and Portlets and the fly likes Namespace in JSF Portlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Namespace in JSF Portlet" Watch "Namespace in JSF Portlet" New topic

Namespace in JSF Portlet

Zuochao Liao

Joined: Apr 10, 2006
Posts: 5
Hi all,

There is an example code about getting namespace in IBM red book 6681:
http://www.redbooks.ibm.com/abstracts/sg246681.html?Open page584

It�s JSF168 project. The workflow is:
a. Open the PageCodeBase.java file. Create the following attribute:
protected String namespace;
b. Create a method to get the portlet namespace from the RenderResponse:

public String getNamespace() {
if (namespace == null) {
RenderResponse response =
namespace = response.getNamespace();
return namespace;

c.In the jsp, change the javascript invoking code:
onchange="return #{pc_Calculate.namespace}func_1(this, event);"

The reason to use value bind to retrieve the namespace in the
onchange attribute is because JSF components does not accept runtime
expressions as values. So you cannot use portlet:namespace here. For this
reason we created a namespace property in PageCodeBase class, with its
proper get method. Inside the JavaScript function, you do not have this
limitation, so you could use the portlet:namespace tag.

My question is: I use IBM Portlet project instead of 168 project.
I get the exception:
Error getting property 'namespace' from bean of type pagecode.ProductView: java.lang.ClassCastException: com/ibm/wps/pe/pc/legacy/impl/PortletResponseImpl incompatible with javax/portlet/RenderResponse

The reason is:
In IBM portlet project �facesContext.getExternalContext().getResponse()� returns com/ibm/wps/pe/pc/legacy/impl/PortletResponseImpl, not javax/portlet/RenderResponse (only for 168 project).

How can I get the namespace in the JSF page in IBM Portlet project? I want to use the namespace to keep my javascript code unique.


Luiz Almeida

Joined: Jun 06, 2006
Posts: 1
Hi Zuochao.

I had the same problem.
I made the getNamespace method to work as well as follow:

public String getNamespace() {
if (namespace == null) {
namespace = facesContext.getExternalContext().encodeNamespace("");
return namespace;

However, I couldn't get the JavaScript method to work :-(

<SCRIPT type="text/javascript">
function <portlet:namespace/>func_1(thisObj, thisEvent) {
return false;

The bold text doesn't work.
If you can get it work, please tell me.


Luiz Almeida
I agree. Here's the link: http://aspose.com/file-tools
subject: Namespace in JSF Portlet
jQuery in Action, 3rd edition