I am creating a portlet for WebSphere portal 8 and would like to retrieve the page name where my portlet is rendered. This is important because depending on the page, the portlet will server content differently

I've tried to use the NavigationSelectionModel API but do not think I'm using it correctly. I want this code to happen before the view is rendered and I put the code in the doView method. The problem is that I cannot cast a ServletRequest/Response because I only have the RenderRequest and RenderResponse available in the doView method.

public void doView(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        // Declarations
        List<ForeignAuthority> faList = new ArrayList<ForeignAuthority>();
        String resp;

        // Set the MIME type for the render response

        // Check if portlet session exists
        ForeignAuthoritiesPortletSessionBean sessionBean = getSessionBean(request);
        if (sessionBean == null) {
            response.getWriter().println("<b>NO PORTLET SESSION YET</b>");

        Context ctx = new InitialContext();
        NavigationSelectionModelHome home = (NavigationSelectionModelHome) 
        if (home != null) {
            NavigationSelectionModelProvider provider = 
            NavigationSelectionModel model = 
                provider.getNavigationSelectionModel((ServletRequest)request, (ServletResponse)response);
            for (java.util.Iterator i = model.iterator(); i.hasNext(); ) 
                NavigationNode node = (NavigationNode) i.next();
                if (i.hasNext()) {
        }catch(Exception e){

        PortletRequestDispatcher rd = getPortletContext()
                .getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
        rd.include(request, response);

The expected result would be to retrieve the page name or unique name of the current page that the portlet is rendered on.

1 Answers

Venkatesh Varadharajan On

You can try whether the below code snippet helps. You can get the URI value and extract the page name from it.

HttpServletRequest httpServletRequest = PortletUtils.getHttpServletRequest(renderRequest); httpServletRequest.getRequestURI();