Well in my recent project i had a requirement to change portlet title at runtime . I followed the following approach suggested by IBM
http://www.ibm.com/developerworks/websphere/library/techarticles/0612_rick/0612_rick.html
After setting the title in RenderResponse.setTitle() method,
you need to have following code to calculate the dynamic portlet id :
public void getDynamicPortletID(RenderRequest request) throws Exception {
String portletId = "";
try {
HttpServletRequest httpRequest = (HttpServletRequest)request;
RunData rundata = RunData.from(httpRequest);
LayoutNode layoutnode =
(LayoutNode) rundata.getAttribute("com.ibm.wps.composition.element");
com.ibm.portal.ObjectID objectid;
if (layoutnode == null)
throw new IllegalStateException("PortletIDTag: Control cannot be found!");
objectid = layoutnode.getObjectID();
if (objectid != null)
portletId = IdentificationMgr.getIdentification().serialize(objectid,false);
}
catch (Exception e) {
e.printStackTrace();
}
}
After calculating the dynamic portletId, with the help of this
portletId use the following code in your
respective JSP
var dynamicTitle = "<%=request.getAttribute(com.ibm.portal.portlet.Constants.DYNAMIC_TITLE)%>";
var titleElement =document.getElementById("title.<%=portletID%>");
if (titleElement != null) {
if(dynamicTitle != "" && dynamicTitle != "null")
titleElement.innerHTML = dynamicTitle;
Note :- This works fine with Mozilla and IE 7.0 browsers.
But has problems with IE 6.0.It gives "Operation TimeOut"
Error.
For reason that why it happeans :-
http://support.microsoft.com/kb/181050
Hence to solve this problem, I used DOJO. As WebSphere Portal Server
implicitly uses DOJO, it was better to find a solution using DOJO
function init() {
var dynamicTitle = "<%=request.getAttribute(com.ibm.portal.portlet.Constants.DYNAMIC_TITLE)%>";
var titleElement =document.getElementById("title.<%=portletID%>");
if (titleElement != null) {
if(dynamicTitle != "" && dynamicTitle != "null")
titleElement.innerHTML = dynamicTitle;
}
}
dojo.addOnLoad( init );
Now it works fine with all the Browzers........
If you have any better approach or any suggestions
to improve this post, please leave a comment below.
Hi Brajesh,
ReplyDeleteThanks for posting this article. I was able to update the title dynamically. One issue i am having is on minimize it reverts back to the original version. I am using V6.0.
-Arjun
Have you put that Dojo script into your JSP bcoz that script is responsible to render dynamic title before portlet content gets render.In that case it shd work fine in Minimize also.
ReplyDeleteFor changing the Portlet Title in WPS , The above mentioned solution and the solutions mentioned in IBM website work fine for Firefox but in case of IE 8 , i was always getting some javascript error , The complete solution that worked for me is as below(some of the typos you have to correct as i could not post the comments, i had to modify the tags) :
ReplyDelete1. first of all locate the Control.jsp for your skin in my case it was :
D:\IBM\wp_profile\installedApps\LNegi\wps.ear\wps.war\skins\html\IBM\Control.jsp
2. Edit this file :
Replace this code :
with
3. In the end of this file append :
function init() {
<% System.out.println("Getting Attribute from Request " + request.getAttribute(com.ibm.portal.portlet.Constants.DYNAMIC_TITLE) ); %>
<% System.out.println("myPortletID" + myPortletID); %>
var dynamicTitle = "<%=request.getAttribute(com.ibm.portal.portlet.Constants.DYNAMIC_TITLE)%>";
var titleElement =document.getElementById("title.<%=myPortletID%>");
if (titleElement != null) {
if(dynamicTitle != "" && dynamicTitle != "null")
titleElement.innerHTML = dynamicTitle;
}
}
dojo.addOnLoad( init );
5. Save the file .
6. Your Portal Application should put the title value in response like RenderResponse.setTitle("Your Title");
7. Access your Portlets in WPS IE8 or Firefox.
Regards
Lalit Negi
Hi Brajesh
ReplyDeleteYour blog has been very helpful. Thanks a ton for sharing the information.
I was searching for the SSO feature in the portals. I came across the credential Vault of IBM but not really sure how feasible it is for implementation of the Single sign-on. Do you have any information on the SSO. If you can provide a walk through of the SSO that you have implemented then it will be of great use for me.
Thanks
Srikanth