|
Home > Archive > WebSphere Portal Server > April 2006 > Namespace in JSF Portlet
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Namespace in JSF Portlet
|
|
|
| Hi all,
There is an example code about getting namespace in IBM red book 6681:
http://www.redbooks.ibm.com/abstrac...46681.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 =
(RenderResponse)facesContext.getExternalContext().getResponse();
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.
Thanks,
George
| |
| yurykats 2006-04-27, 8:07 am |
| PortletResponse response =
(PortletResponse)facesContext.getExternalContext().getResponse();
namespace = response.encodeNamespace("");
| |
|
| I solved this issue by using:
com.ibm.wps.pe.pc.legacy.impl.PortletResponseImpl response = (com.ibm.wps.pe.pc.legacy.impl.PortletResponseImpl) facesContext
.getExternalContext().getResponse();
namespace = response.encodeNamespace("");
|
|
|
|
|