@Override protected void initBridgeRequestScope( PortletRequest portletRequest, PortletResponse portletResponse, PortletPhase portletPhase) { super.initBridgeRequestScope(portletRequest, portletResponse, portletPhase); // If the portlet container does not support the POST-REDIRECT-GET design pattern, then the // ACTION_PHASE and // RENDER_PHASE are both part of a single HTTP POST request. In such cases, the excluded request // attributes must // be pro-actively removed here in the RENDER_PHASE (providing that the bridge request scope was // created in the // ACTION_PHASE). Note that this must take place prior to the FacesContext getting constructed. // This is because // the FacesContextFactory delegation chain might consult a request attribute that is supposed // to be excluded. // This is indeed the case with Apache Trinidad {@link // org.apache.myfaces.trinidadinternal.context.FacesContextFactoryImpl.CacheRenderKit} // constructor, which // consults a request attribute named "org.apache.myfaces.trinidad.util.RequestStateMap" that // must first be // excluded. PortalContext portalContext = portletRequest.getPortalContext(); String postRedirectGetSupport = portalContext.getProperty(BridgePortalContext.POST_REDIRECT_GET_SUPPORT); if ((postRedirectGetSupport == null) && (bridgeRequestScope.getBeganInPhase() == Bridge.PortletPhase.ACTION_PHASE)) { bridgeRequestScope.removeExcludedAttributes(renderRequest); } }
protected void doHeaders(RenderRequest request, RenderResponse response) { super.doHeaders(request, response); PortalContext portalContext = request.getPortalContext(); String portalInfo = portalContext.getPortalInfo(); // -- adding DOM element to head is supported by JetSpeed 2.2 if (portalInfo.contains(Constants.JETSPEED)) { // -- add CSS Element cssElement = response.createElement("link"); // --encoding URLs is important cssElement.setAttribute( "href", response.encodeURL((request.getContextPath() + "/css/bookCatalog.css"))); cssElement.setAttribute("rel", "stylesheet"); cssElement.setAttribute("type", "text/css"); response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, cssElement); // -- add JavaScript Element jsElement = response.createElement("script"); // --encoding URLs to resources is important jsElement.setAttribute( "src", response.encodeURL((request.getContextPath() + "/js/bookCatalog.js"))); jsElement.setAttribute("type", "text/javascript"); response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, jsElement); } }
private void printSupportedWindowStates(PortalContext context) { // -- supported window states by the portal server Enumeration<WindowState> windowStates = context.getSupportedWindowStates(); while (windowStates.hasMoreElements()) { WindowState windowState = windowStates.nextElement(); logger.info("Support window state " + windowState.toString()); } }
private void printSupportedPortletModes(PortalContext context) { // -- supported portlet modes by the portal server Enumeration<PortletMode> portletModes = context.getSupportedPortletModes(); while (portletModes.hasMoreElements()) { PortletMode mode = portletModes.nextElement(); logger.info("Support portlet mode " + mode.toString()); } }
@SuppressWarnings("unchecked") @RenderMode(name = "VIEW") public void showBooks(RenderRequest request, RenderResponse response) throws IOException, PortletException { logger.info("Entering showBooks method"); PortalContext context = request.getPortalContext(); printSupportedPortletModes(context); printSupportedWindowStates(context); // --get user attributes user.name.given and user.name.family Map<String, Object> userAttributeMap = (Map<String, Object>) request.getAttribute(PortletRequest.USER_INFO); String firstName = ""; String lastName = ""; if (userAttributeMap != null) { firstName = (String) userAttributeMap.get("user.name.given"); lastName = (String) userAttributeMap.get("user.name.family"); request.setAttribute("firstName", firstName); request.setAttribute("lastName", lastName); } String portalInfo = context.getPortalInfo(); request.setAttribute("portalInfo", portalInfo); // --generate all the URLs that will be used by the portlet generateUrls(request, response); String myaction = request.getParameter("myaction"); if (myaction != null) { logger.info("myaction parameter is not null. Value is " + myaction); request.getPortletSession().setAttribute("myaction", myaction, PortletSession.PORTLET_SCOPE); } else { // -- if myaction is NULL then show the home page of Book // catalog // page request .getPortletSession() .setAttribute("myaction", "showCatalog", PortletSession.PORTLET_SCOPE); } // -- send myaction as a request attribute to the BookServlet. request.setAttribute("myaction", request.getPortletSession().getAttribute("myaction")); // --dynamically obtain the title for the portlet, based on myaction String titleKey = "portlet.title." + (String) request.getPortletSession().getAttribute("myaction"); response.setTitle(getResourceBundle(request.getLocale()).getString(titleKey)); // --if the action is uploadTocForm then store the ISBN number of // the // --book for which the TOC is being uploaded. The upload action // will use the ISBN number to create file name -- refer home.jsp // page if (((String) request.getAttribute("myaction")).equalsIgnoreCase("uploadTocForm")) { request.getPortletSession().setAttribute("isbnNumber", request.getParameter("isbnNumber")); } if (((String) request.getPortletSession().getAttribute("myaction")) .equalsIgnoreCase("showSearchResults")) { request.setAttribute( "matchingBooks", request.getPortletSession().getAttribute("matchingBooks")); } // its important to encode URLs PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); }