Question

I am working on a JSR 286 Portlet (Portlet spec 2.0). I have some values I am trying to set on the JSP, which I am setting in my Java code via session.setAttribute(). However, I cannot seem to be able to get the attribute back out of the PortletSession in the JSP without using the portlet namespaced name.

My understanding of the JSR 286 and PortletSession is this:

  • Each portlet will be given it's own "portlet session", which is a sub-section of the HttpSession from the web container
  • Attributes added to the "portlet session" will only be visible to that portlet
  • The separation is done by adding a namespace to the attributes, in the form of "javax.portlet.p.?", where is a unique identifier for the Portlet and is te name of the attribute.

In reading this, I was under the impression that using the portletSessionScope object in the JSP would give me de-referenced access to the attribute, allowing me to get the values back out similar to how you do it in plain-ol JSP code and HttpSession. However, it appears not to be the case.

Take the following Java code:

private static void processGetMessage(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    PortletSession session = request.getPortletSession();
    session.setAttribute("MESSAGE", "This is a sample message", PortletSession.PORTLET_SCOPE);
}

I would expect the following to work fine in the JSP code:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0" %>
<portlet:defineObjects/>
<html>
  <body>
    <div>
       ${portletSessionScope.MESSAGE}
    </div>
  </body>
</html>

However I get nothing printed in the <div> tags. I have also tried:

  • ${portletSessionScope.sessionData.MESSAGE}
  • ${portletSessionScope[MESSAGE]}
  • ${portletSessionScope["MESSAGE"]}
  • <%=portletSession.getAttribute("MESSAGE", PortletSession.PORTLET_SCOPE)%>

As well as a few others. However, if I print out all of the variables in pageSessionScope like this:

<table>
    <c:forEach items="${portletSessionScope}" var="s">
        <tr><td>${s.key}</td><td>${s.value}</td></tr>
    </c:forEach>
</table>

I see it's there, just pre-pended with the portal ID like this:

javax.portlet.p.9f4396132993df65a8017810d6c48a0c-a6f0dbfb9072591830fbfb10d6c48a0c-96d16bb01556c9c7725e4632d6c48a0c?MESSAGE

If I take that and past it into the following: <%=portletSession.getAttribute("javax.portlet.p.9f4396132993df65a8017810d6c48a0c-a6f0dbfb9072591830fbfb10d6c48a0c-96d16bb01556c9c7725e4632d6c48a0c?MESSAGE", PortletSession.PORTLET_SCOPE)%>

or even

${portletSessionScope["javax.portlet.p.9f4396132993df65a8017810d6c48a0c-a6f0dbfb9072591830fbfb10d6c48a0c-96d16bb01556c9c7725e4632d6c48a0c?MESSAGE"]}

Then it works just fine.

So, the questions:

  1. Why is the simple form using JSTL and EL not working?
  2. Is it possible to get JSTL/EL working as I was expecting they should?
  3. If not, how can I get the value of the namespace used to prepend to the attribute name? It's not simply the value from <portal:namespace>, it seems to have some specific instance ID information on it as well.

In case it helps identify the problem we are on WebLogic 9.2 and Vignette 7.4.

Was it helpful?

Solution

After speaking with the vendor, it appears to be a known bug in the version of Vignette portal that we are currently on. The bug is that they are improperly building the map of PortletSession variables to include all Session variables instead of just the PortletSession ones, which in turn includes the "javax.portlet.p.?" on the front of all the names. The fix will ultimately be to move to a newer version, which we currently are in the process of doing anyways. In the meantime, I am using scriptlet (shutters to think...) to copy the variable straight from the PortletSession into pageContext like so:

<portlet:defineObjects/>
<%
    PortletSession sess = renderRequest.getPortletSession();
    pageContext.setAttribute("message", sess.getAttribute("MESSAGE"));
%>

After which I am able to simply use JSTL/EL to get the message value back out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top