Showing posts with label portlet development. Show all posts
Showing posts with label portlet development. Show all posts

Thursday, April 16, 2009

Cross page portlet communication in WebSphere Portal Server using URL Generation API

How can I make communication between two portlet without using wires when you want to paas parameters from one portlet to other and that shoud be used by second portlet.
Well this can be achieved using URL Generation API, just use the code below on your SourceJSP of SourcePortlet.In the code below, PAGE_UNIQUE_NAME would be page name on which you have target portlet and Portlet name would be your target portlet name.Params would be your parameters that you want to pass to target portlet.

String homeURL = PortletURLHelper.generateUrl(PAGE_UNIQUE_NAME, Portlet Name, HashMap params, renderRequest, renderResponse);

you can get param values in target portlet using the following code

Map map = renderRequest.getParameterMap();

now just iterate the map and find the values you passed from source portlet.

Saturday, April 4, 2009

Know How to Change a Portlet Title at "Run Time" in WebSphere Portal V6!

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.