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
Luiz Almeida
Greenhorn
Joined: Jun 06, 2006
Posts: 1
posted
0
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 :-(