{
UIPortal showedUIPortal = event.getSource();
UIPortalApplication uiPortalApp = showedUIPortal.getAncestorOfType(UIPortalApplication.class);
//This code snippet is to make sure that Javascript/Skin is fully loaded at the first request
UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
PortalRequestContext pcontext = Util.getPortalRequestContext();
pcontext.setFullRender(true);
pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
PageNavigation currentNav = showedUIPortal.getSelectedNavigation();
String currentUri = showedUIPortal.getSelectedNode().getUri();
if(currentUri.startsWith("/"))
{
currentUri = currentUri.substring(1);
}
//This if branche is to make sure that the first time user logs in, showedUIPortal has selectedPaths
//Otherwise, there will be NPE on BreadcumbsPortlet
if(showedUIPortal.getSelectedPath() == null)
{
List<PageNode> currentSelectedPath = findPath(currentNav, currentUri.split("/"));
showedUIPortal.setSelectedPath(currentSelectedPath);
}
String targetedUri = ((PageNodeEvent<UIPortal>)event).getTargetNodeUri();
if(targetedUri.startsWith("/"))
{
targetedUri = targetedUri.substring(1);
}
PageNavigation targetedNav = getTargetedNav(uiPortalApp, targetedUri);
if(targetedNav == null)
{
return;
}
String formerNavType = currentNav.getOwnerType();
String formerNavId = currentNav.getOwnerId();
String newNavType = targetedNav.getOwnerType();
String newNavId = targetedNav.getOwnerId();
String[] targetPath = targetedUri.split("/");
PageNode targetPageNode = getTargetedNode(targetedNav, targetPath);
List<PageNode> targetedPathNodes = findPath(targetedNav, targetPath);
if(formerNavType.equals(newNavType) && formerNavId.equals(newNavId))
{
//Case 1: Both navigation type and id are not changed, but current page node is changed
if(!currentUri.equals(targetedUri))
{
showedUIPortal.setSelectedNode(targetPageNode);
showedUIPortal.setSelectedPath(targetedPathNodes);
}
}
else
{
// Case 2: Either navigation type or id has been changed
// First, we try to find a cached UIPortal
uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
showedUIPortal = uiPortalApp.getCachedUIPortal(newNavType, newNavId);
if (showedUIPortal != null)
{
showedUIPortal.setSelectedNode(targetPageNode);