Kevin Irmscher escribió:
Hi!
I'm developping a portlet and I want to use the PortletSession to pass
attributes between the Portlet and a JSP. This works perfectly when I
deploy the portlet locally (Pluto), but it doesn't when I access the
portlet through WSRP using WSRP4J (with Pluto) as producer.
Here's what I'm doing exactly:
1. invoke an actionURL in the JSP
2. processAction in the portlet will be called
3. set PortletSession attribute (the attribute is an object of MyClass)
actionRequest.getPortletSession().setAttribute("myClass", new
MyClass());
4. get MyClass object in JSP
<%
MyClass c = (MyClass)
renderRequest.getPortletSession().getAttribute("myClass");
%>
5. display c.toString
<% if (c != null) { %> <%=c.toString()%> <% } %>
It does work if the portlet is local but not when I consume it
remotely. That's why I assume it must have something to do with the
WSRP4J producer implementation. I don't get any error messages neither
on the consumer nor on the producer.
It is strange tough that if I use a String or an Integer object
instead of MyClass it even works with WSRP4J!
Any help would be appreciated,
Kevin
Here the code of the portlet:
public class SessionTestPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
PortletContext context = getPortletContext();
PortletRequestDispatcher disp =
context.getRequestDispatcher("/jsp/"
+ "view.jsp");
disp.include(request, response);
}
public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws PortletException,
java.io.IOException {
actionRequest.getPortletSession()
.setAttribute("myClass", new MyClass());
}
}
Here the code of view.jsp:
<%@ page session="true"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@ page import="javax.portlet.*"%>
<%@ page import="java.util.*"%>
<%@ page import="session.test.portlet.MyClass"%>
<portlet:defineObjects />
<%
MyClass c = (MyClass)
renderRequest.getPortletSession().getAttribute("myClass");
%>
<%
if (c == null) {
%>
<form action="<%=renderResponse.createActionURL()%>" method="post">
<input type="submit" value="Show MyClass" /></form>
<% } else { %>
<%=c.toString()%>
<% } %>
Your code seems correct and besides that, if it works as a local portlet
it should work exposed by WSRP4J Producer.
Which consumer are you using? Are you sure the WSRP processAction()
operation is being called? Check the SOAP communication for details.
Take into account that the only tested Pluto version is 1.0.1, not the
recent 1.1.0.
The logs (for both the consumer and producer) should give you any clues
on the problem. That thing on working with Java wrapper types but not
with custom classes is strange. Are you sure the producer is accesing
the jars with your custom classes?
You can also use netbeans or eclipse debugger to check what the code is
doing as a last resort.
Regards.
Diego.