Creating a URL to portlet in solo state

In the Using PortletStateManagerService for creating URLs from within the portlet blog i talked about how to create a URL to portal page from inside portlet.

But what if you want to create a URL to portlet in solo state, in the solo state WebSphere portal wont display navigation of the page and looks much better suited for opening portal page in dialog box. You can use following code to create a URL to portlet in solo state


private String getPortletSoloStateURL(PortletRequest request,
PortletResponse response) {
PortletStateManager portletStateManager = null;
try {
portletStateManager = portletStateManagerService
.getPortletStateManager(request, response);
final URLFactory urlFct = portletStateManager.getURLFactory();
final EngineURL url = urlFct.newURL(null);

final SelectionAccessorFactory selectionAccessorFactory = portletStateManager
.getAccessorFactory(SelectionAccessorFactory.class);
SelectionAccessorController selectionAccessorCOntroller = selectionAccessorFactory
.getSelectionController(url.getState());
selectionAccessorCOntroller
.setSelection("com.webspherenotes.popup.static");

final PortletAccessorFactory portletFct = (PortletAccessorFactory) portletStateManager
.getAccessorFactory(PortletAccessorFactory.class);
final PortletAccessorController portletCtrl = portletFct
.getPortletController("com.webspherenotes.popup.control",
url.getState());
portletCtrl.getParameters().put("userName",
new String[] { "soloStateSample" });

final SoloAccessorFactory soloAccessorFactory = portletStateManager.getAccessorFactory(SoloAccessorFactory.class);
SoloAccessorController soloStateController = soloAccessorFactory.getSoloAccessorController(url.getState());
soloStateController.setSoloPortlet("com.webspherenotes.popup.control");

String finalURL = url.toString();
System.out.println("Portal Page URL " + finalURL);
return finalURL;
} catch (InvalidConstantException e) {
e.printStackTrace(System.out);
} catch (CannotInsertSelectionNodeException e) {
e.printStackTrace(System.out);
} catch (CannotCloneDocumentModelException e) {
e.printStackTrace(System.out);
} catch (CannotCreateDocumentException e) {
e.printStackTrace(System.out);
} catch (StateNotInRequestException e) {
e.printStackTrace(System.out);
} catch (MissingUniqueNameException e) {
e.printStackTrace(System.out);
} catch (UnknownUniqueNameException e) {
e.printStackTrace(System.out);
} catch (StateManagerException e) {
e.printStackTrace(System.out);
} catch (UnknownAccessorTypeException e) {
e.printStackTrace(System.out);
} catch (CannotInstantiateAccessorException e) {
e.printStackTrace(System.out);
} catch (CannotInstantiateURLFactoryException e) {
e.printStackTrace(System.out);
}
return null;
}


You can use the SoloAccessorFactory for invoking a portlet in solo state. This is how my target page looks like in the solo state

1 comment:

Hélder Sousa said...

Hi Sunil,

Is that example working for you? Even if you have two portlets in the target page? Can you provide an example working?
Thank you.

Helder Sousa