Inter Portlet Communication - Portlet Session
leonard89 Jun 12, 2013 8:28 AMI am doing a simple project on portlets. It is deployed in gatein portal by Jboss. However, I have encountered some problems on PortletSession which I don't understand.
Context: I have developed 2 portlets within the same .war file. Portlet A is a search portlet and Portlet B is used to display the result of the search. The problem that I am facing is Portlet B not displaying the search result after I have done a search request using Portlet A. I have used PortletSession to pass an arraylist to Portlet B to display the result. After some debugging, i realized that the VIEW is not invoke after the search request.
Below is the snippet of codes from Portlet A and B.
//ProcessAction from Portlet A- search listing
@ProcessAction(name = "searchListing")
public void searchListing(ActionRequest request, ActionResponse response) {
ArrayList<Listing> result = new ArrayList<Listing>();
try {
if (request.getParameter("name") != null || !request.getParameter("name").equals("")) {
String name = request.getParameter("name");
String address = request.getParameter("address");
String category = request.getParameter("category");
result = ListingManager.retrieveListingList(name, address, category);
request.getPortletSession().setAttribute("resultList", result, PortletSession.APPLICATION_SCOPE);
}
} catch (Exception e) {
// e.printStackTrace();
}
}
//RENDER VIEW from Portlet B - display search results.
@RenderMode(name = "view")
public void display(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
ArrayList<Listing> resultList = (ArrayList<Listing>)request.getPortletSession().getAttribute("resultList",PortletSession.APPLICATION_SCOPE);
if(resultList == null){
resultList = new ArrayList<Listing>();
}
request.setAttribute("result", resultList);
getPortletContext().getRequestDispatcher(response.encodeURL("/html/helloWorld.jsp")).include(request, response);
}