Using jsp:param / c:param in a Portlet Environment

I'm trying to include JSP pages with jsp:param in a Portlet environment (using the Pluto portlet container).

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?

Answers


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.


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...

Need Your Help

Bash test and execute if directory pattern exists

linux bash shell

How do you do an inline test for the existence of a directory pattern?

Loading shapes to a map with DrawingManager Instance

google-maps-api-3

I want to load shapes to my all_overlays array where I'm storing the shapes

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.