*/
private void setDefaultView(FacesContext facesContext, String defaultView, String viewId)
{
// Need to be able to transport viewId between actionRequest and
// renderRequest.
PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
if (portletRequest instanceof ActionRequest)
{
String view = (String)portletRequest.getPortletSession().getAttribute(viewId, PortletSession.PORTLET_SCOPE);
if ((null != facesContext.getViewRoot()) && (null != facesContext.getViewRoot().getViewId()))
{
defaultView = facesContext.getViewRoot().getViewId();
}
//else if (null != portletRequest.getParameter(viewId))
else if (null != view)
{
//defaultView = portletRequest.getParameter(viewId);
defaultView = view;
}
UIViewRoot viewRoot = (UIViewRoot)portletRequest.
getPortletSession().
getAttribute(createViewRootKey(facesContext, defaultView, viewId));
if (viewRoot != null)
{
facesContext.setViewRoot(viewRoot);
defaultView = facesContext.getViewRoot().getViewId();
}
portletRequest.setAttribute(REQUEST_SERVLET_PATH, defaultView.replaceAll("[.]jsp", ".jsf"));
}
else if (portletRequest instanceof RenderRequest)
{
// String view = portletRequest.getParameter(viewId);
String view = (String)portletRequest.getPortletSession().getAttribute(viewId, PortletSession.PORTLET_SCOPE);
if (null == facesContext.getViewRoot())
{
if (view == null)
{
view = defaultView;
}
UIViewRoot viewRoot = (UIViewRoot)portletRequest.
getPortletSession().
getAttribute(createViewRootKey(facesContext, view, viewId));
if (null != viewRoot)
{
facesContext.setViewRoot(viewRoot);
defaultView = facesContext.getViewRoot().getViewId();
}
else
{
facesContext.setViewRoot(new UIViewRoot());
facesContext.getViewRoot().setViewId(view);
facesContext.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
portletRequest.getPortletSession().setAttribute(createViewRootKey(facesContext, view, viewId), viewRoot);
}
}
portletRequest.setAttribute(REQUEST_SERVLET_PATH, view.replaceAll(".jsp", ".jsf"));
}
}