Importance of Portlet namespace

JSR 168 tag lib provides a tag <portlet:namespace/> which is responsible for differentiating two javascript functions with the same name in different portlets placed on the same page.
got confused???

let us talk practically...

Portlet A is developed by developer A and portlet B is developed by developer B and both have kept their portlet on the same page.
Both portlets has a submit button.

Now, there would always be higher possibility that both the portles have the same java script function name for submit button, and when you hit submit button of portlet A, which javascript submit function will be called? you can never say, because both the portles have exactly same function name.

To overcome this issue, JSR 168 introduced portlet namespace which differentiate two javascript functions with the same name.

By applying <portlet:namespace/> with a java script function, it generates a unique alpha numeric string for each portlet and append it to function name.

// namespaced javascript function
function submit<portlet:namespace/>(){
// function code
this will internally converted into
function submitns_7_CGAH47L00GSJC0IOF0L4TT30G7_(){
// function code
and makes it unique javascript function

// call to function
<a href="onClick='submit<portlet:namespace/>()'>Submit</a>

As per JSR168 portlet best practice, one should always namepsace
javascript functions.
example:- function submit<portlet:namespace/>(){ }
Form Name.
example :- <form name="formOne<portlet:namespace/>" action="<portlet:actionURL/>">
javascript global variables.

Important, you can also get portlet name space from RenderRequest
String portletNameSpace = renderResponse.getNamespace();

1 comment:

mohammed said...

i need even more clarification
!!thank you!!