my dog learned polymorphism*
The moose likes Portals and Portlets and the fly likes encode namsepace in portlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "encode namsepace in portlets" Watch "encode namsepace in portlets" New topic
Author

encode namsepace in portlets

geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
as per my understanding, when we use things like javascript, we use the
<portletapi:encodenamespace tag to encode the function name.

This is to avoid the conflict between the namespace for jsp on the other portlet, in the same portal.

Now, what i tried is that, i put the same portlets on the same page. i.e 2 similar concrete portlets are placed on the same page. Encoded the namespace.

Note: i havent encoded each field on the jsp.
When we submit the jsp, it gives javascript error. If you see view source of the page , the encoding is the same,
why so?
what to do in case i need the same portlets twice on the same page?

Note: it works fine if only one portlet is placed on the page.
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
What do you mean by "submit the jsp". If the system display your JSP without any error, please check the HTML source code and check whether the JavaScript names have unique identifiers?

Btw: Which portlet container do you deploy on? I have successfully used this tag within JSPs on IBM WebSphere portal, and no problems with a portlet used twice within a page appeared.


Stefan Zoerner
Author of German LDAP-Book
Committer at Apache Directory Project
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
Thanks stefan....

but i dont understand how did it work for u..
even i use IBM Websphere Portal Server...

n i checked the source... the encoding is same.. so they have the same identifiers for the javascript n they are not unique.

Can u please tell me if u suspect i m doing something wrong....
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Hi Geetu!

Here is a sample JSP fragment. It defines a JavaScript function to focus the cursor in a textfield. Later on, the function is used in a JavaScript event (please note that I had to change the name to "onmMAUSover" in order to post the code here).

The name of the function is prefixed with the namespace tag to ensure it is unique in the HTML page.


If the portlet which uses this JSP is placed several times on a page, no errors occur, but the function is declared with different names per portlet appearance, and is called accordingly.

Hope it helps, Stefan
[ December 14, 2005: Message edited by: Stefan Zoerner ]
Mohammed Fayaz
Greenhorn

Joined: Jan 19, 2006
Posts: 4
Hi All,
I am very new to portlets.
To reuse the javascript functions I have a external ".js" file.
I am planning to use this javascript functions in JSPs for some
portlets. The problem is how will One encode the function names
which are in external ".js" file? Can it be done? what is way
out to re-use the javascript functions with encoded names?

Thanks for all your efforts in advance
Fayaz
Jimmy Ho
Ranch Hand

Joined: Jul 31, 2007
Posts: 61
Re: Using external .js files

As a former IBMer who has had to research this question for more than one client, the answer is: You cannot namespace-encode anything in an external .js file. There's just no way to do it.

This definitely applies for WebSphere Portal 5.1.x.x, and very, very likely for Portal 6.0.

Alternative 1: Import it now as an external .js file, but as a JSP file. This may have performance issues since .js files can be put on the webserver, and don't have server-side code to run.

Alternative 2: You can just manually handle the encoding. In other words, just coordinate with all your developers to use manual prefixes on the relevant JavaScript variables. So instead of changing myString to 07_A3259D8myString, just encode it to stockQuotePortlet_myString. The downside is that if you have a lot of different stakeholders running around coding their own portlets, doing this can be a coordination nightmare. Anyway, if you do this, then of course, in the .js file, you can namespace-encode the variables and function names because the namespace strings are not dynamically generated.

Alternative 3: Just don't namespace-encode them. Or rather, if this really is a 'global' .js file that can be used by multiple portlets, then just put the import in the theme or something, and just make sure the names don't conflict with existing Portal JavaScript names. You can usually do this by prefixing all the relevant names with something that you know will definitely not be in the Portal product.

Hope this helps.
[ August 07, 2007: Message edited by: Jimmy Ho ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: encode namsepace in portlets
 
Similar Threads
Portlets-Servlets-what's the difference
Websphere Portal - Test 399
J2EE Application to Portlet
Recommendations for Development Environment
WebSphere Portal Server Qs