Wouldn't it be possible to extract the getting viewId logic from MainPortlet.render method to separate protected method as a part of this fix? TO be more precisely, this code:
// Get the inital view that is configured in the portlet.xml file
PortletMode portletMode = renderRequest.getPortletMode();
String viewId = null;
if (portletMode == PortletMode.VIEW) {
viewId = portletConfig.getInitParameter(Constants.VIEW_KEY);
if (viewId == null) {
if (log.isErrorEnabled())
{
log.error(Constants.VIEW_KEY + " is not properly configured");
}
throw new PortletException(Constants.VIEW_KEY + " is not properly configured");
}
} else if (portletMode == PortletMode.EDIT) {
viewId = portletConfig.getInitParameter(Constants.EDIT_KEY);
if (viewId == null) {
if (log.isErrorEnabled())
{
log.error(Constants.EDIT_KEY + " is not properly configured");
}
throw new PortletException(Constants.EDIT_KEY + " is not properly configured");
}
} else if (portletMode == PortletMode.HELP) {
viewId = portletConfig.getInitParameter(Constants.HELP_KEY);
if (viewId == null) {
if (log.isErrorEnabled())
{
log.error(Constants.HELP_KEY + " is not properly configured");
}
throw new PortletException(Constants.HELP_KEY + " is not properly configured");
}
}
It would be useful to have an ability to override this logic in the subclasses. Personally, I'd like to add an ability to show some view based on request parameters.
This attribute name is not presented around the names returned by request.GetAttributeNames() but it's value returned by request.getAttribute("javax.protlet.response") (see attachment).
I don't know whether this is a Liferay bug or feature but strictly speaking they do exactly what specification says:
"These attributes must be the same Portlet API objects accessible to the portlet doing the
include call. They are accessible from the included servlet or JSP via the
getAttribute method on the HttpServletRequest object."
No any word about request.GetAttributeNames() ...