How to get the JBoss Portal window name, page name, and portal name for a JSF portlet

Posted by on January 12, 2009

Recently I needed one of my JSF portlets running in JBoss Portal to know some information about itself.  The information I needed was:

  • Window name
  • Page name
  • Portal name

Surprisingly it was not easy to figure out how to do this. Not because it’s not feasible, it’s just that the information was simply not there for the common developer to find (forums, Google, etc.).  So I thought it would be worthwhile to share my findings.

This is what you need to do:

// Get render request object that contains needed info
JBossRenderRequest req =
    (JBossRenderRequest) FacesContext.getCurrentInstance()
        .getExternalContext().getRequest();
// Extract window name for this portlet
String windowName = req.getPortalNode().getName();
// Extract page name for this window
String pageName = req.getPortalNode().getParent().getName();
// Extract portal name
String portalName = null;
PortalNode portalNode = req.getPortalNode();
PortalNode rootNode = req.getPortalNode().getRoot();
while (true) {
    portalNode = portalNode.getParent();
    if (!rootNode.equals(portalNode)) {
        portalName = portalNode.getName();
    } else {
        break;
    }
}
Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. dan Jun 16, 2009 17:13

    The first line of code does not work for me using JBoss EPP 4.3 and RichFaces. I get this message: java.lang.ClassCastException: org.jboss.portal.portlet.impl.jsr168.api.ActionRequestImpl cannot be cast to org.jboss.portlet.JBossRenderRequest

    So I did i this way and it worked!
    PortalNode node = Navigation.getCurrentNode();
    Then I switched all of your “req.getPortalNode().” to “node.” and it worked fine. Weird!

  2. Zoha Aug 14, 2009 05:11

    May i know how to access all these from this page? deploy/jboss-portal.sar/portal-server.war/login.jsp…

    I have 2 different portals in my jboss and they have different login pages… i am trying to differentiate the portals in login.jsp and redirect their page to their related login pages…

    if i try to get the portal like this–>> PortalNode node = (PortalNode)request.getAttribute(”org.jboss.portal.api.PORTAL_NODE”); it throws null pointer!..

    Thank you for your very useful blog…

  3. Xavier Dec 23, 2009 11:40

    Thanks.. This Information was useful

  4. vette is fast Jul 12, 2010 13:47

    You gave great points here. I did some research on this subject and have found nearly all people agree with your website.

    Sent from my Android phone

Comments

Comments: