How to generate a PortletURL in CAF Notifications

Hello,

I would like to include a link in a CAF Notification that points to a portlet. So I tried the following code:

IPortletURL portletURL = PortletURLFactory.createRenderUrl(getFacesContext());

This call fails with this exception:

2011-03-23 14:27:26 CET (/investapplicationtasks:INFO)  - Unable to create portlet url when without portlet container

The problem here seems to be that facesContext.getExternalContext().getResponse() returns a ServletResponse and no RenderResponse.

Is there any way to create a portlet URL in a CAF Notification.

Any ideas are highly appreciated.

Regards,
Mathias

I’m sorry, but this isn’t currently supported. You have a very valid use case and a reasonable expectation to use the API, but as you’ve noted our API expects to be invoked in a Request/Response cycle which doesn’t exist when rendering notifications.

I don’t have a document that describes the internal workings of our Portlet URLs, but if you have simple enough requirements you can probably generate this at runtime.

One way to go about this is to create a throwaway application that using the APIs or PortletURL controls, generates the appropriate URL. Then you could extract out the Format of the URL and in your notification view, inject the appropriate values. The real trick will be if you are setting properties on a portlet at runtime. The dbID of that portlet will change from environment to envionment so you’ll have to obtain that dynamically.

Regards,
–mark

Thanks for the response.

I already tried to generate the portlet URL by hand using

URLUtils.getFrontEndURL(getFacesContext());

and a page alias. The hard part are the parameters that have to be prefixed with a generated string. This string seems to contain the portlet id. So a parameter myParam becomes wmp31221.myParam where 31221 is the portlet id. Is that right? Is there a way to obtain this id using a MWS API using a portlet alias?

Regards,
Mathias

Yes, you’re on the right track.

Here’s the code requested to get the dbid from an alias:

import com.webmethods.portal.system.IURI;
import com.webmethods.portal.system.PortalSystem;
import com.webmethods.portal.system.PortalException;
import com.webmethods.portal.service.meta2.thing.IThingID;


public int getDbID(String uriOrAlias) throws PortalException { 
    int dbID = -1; 
    IURI uri = PortalSystem.getPortalSystem().acquireURI(uriOrAlias); 
    if(uri instanceof IThingID) { 
        dbID = ((IThingID)uri).getDbID(); 
    } 
    return dbID; 
} 

Regards,
–mark

Hi Mark,

great - thanks for the snippet.

Regards,
Mathias