tags:

views:

262

answers:

3

I'm just trying to include jsp pages with jsp:param in a portlet environment (using pluto)

for example,

<jsp:include page="test.jsp">
   <jsp:param name="foo" value="bar"/>
</jsp:include>

and in test.jsp,

<c:out value="${foo}"/> or <%= request.getParameter("foo") %>

The output is always null and i've also tried using c tags, but got the same result.

<c:import url="test.jsp">
   <c:param name="foo" value="bar"/>
</c:import>

I've searched through the net and many people have faced the same problem, except that there is no solution to it.

Is this a limitation or is there a different way to do it?

+1  A: 

This works fine in a normal Servlet environment, but I see from a bit of googling that the portlet environment seems to break it. This is a shame, but indicative that the portlet spec is, to put it bluntly, broken.

If <jsp:param> won't work for you, the alternative is to use request attributes instead:

<c:set var="foo" value="bar" scope="request"/>
<jsp:include page="test.jsp"/>

And in test.jsp:

<c:out value="${requestScope.foo}"/>

or maybe just:

<c:out value="${foo}"/>

It's not as neat and contained as using params, but it should work for portlets.

skaffman
That's correct. I would however add that the portlet API's offers builtin ways/taglibs to go around this. I have never done portlets so don't pin me on it, but quickly scanning the docs learns me that under each `<portlet:param>` would be the way to go.
BalusC
A: 

I had the same problem. My solution was to work with Portlet's renderRequest object (which is accessible from included jsp files). In my portlet I set the attribute on the RenderRequest object then in my JSP (included via jsp:include). I use Portlet API to access the implicit renderRequest object. Here is a sample:

MyPortlet:

public void doView(RenderRequest request, RenderResponse response) {
  request.setAttribute("myBean", new MyBean());
  getPortletContext().getRequestDispatcher("myMainJSP.jsp").include(request, response);
}

myMainJSP.jsp:

<jsp:include page="header.jsp"/>

header.jsp:

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<% page import="sample.MyBean" %>
<portlet:defineObjects/>
<%
  MyBean myBean = (MyBean)renderRequest.getAttribute("myBean");
%>
... html code...
Richard
A: 

Sounds good. Thanks I'll look into that :)

Richard