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); } }
@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); }