ServletContext servletContext = pageContext.getServletContext();
DriverConfiguration driverConfig = (DriverConfiguration)
servletContext.getAttribute(AttributeKeys.DRIVER_CONFIG);
// Retrieve the portal environment.
PortalRequestContext portalEnv = PortalRequestContext.getContext(
(HttpServletRequest) pageContext.getRequest());
//find the current mode for use in 'selected' attrib of select option
PortalURL requestedPortalUrl = portalEnv.getRequestedPortalURL();
PortletWindowConfig windowConfig =
PortletWindowConfig.fromId(evaluatedPortletId);
// Retrieve the portlet container from servlet context.
PortletContainer container = (PortletContainer)
servletContext.getAttribute(AttributeKeys.PORTLET_CONTAINER);
// Create the portlet window to render.
PortletWindow window = new PortletWindowImpl(container, windowConfig, requestedPortalUrl);
PortletMode currentMode = requestedPortalUrl.getPortletMode(window.getId().getStringId());
//start the markup
StringBuffer tag = new StringBuffer();
// String strCurrentMode = currentMode.toString();
// tag.append("Current mode: " + currentMode.toString());
tag.append("<form action=\"\" name=\"modeSelectionForm\" style=\"display:inline\"><select onchange=\"self.location=this.options[this.selectedIndex].value\">");
Set<PortletMode> modeSet = null;
try {
modeSet = driverConfig.getSupportedPortletModes(evaluatedPortletId);
} catch (PortletContainerException e) {
throw new JspException(e);
}
if (modeSet != null) {
Iterator<PortletMode> i = modeSet.iterator();
while (i.hasNext()) {
PortletMode mode = i.next();
PortalURL portalUrl = portalEnv.createPortalURL();
portalUrl.setPortletMode(evaluatedPortletId, mode);
// Build a string buffer containing the anchor tag
tag.append("<option value=\"" + portalUrl.toString() + "\"");
//Add 'selected' attribute for current mode.