0

I'm trying to communicate between two portlets by rendering the URL.

One portlet shows the table containing the list of available options. When one of the options is clicked, a javascript function renders the URL and in the second portlet should appear the detailed info about the clicked project.

However, it is not working: the URL is rendered correctly, with the proper id of the row in the URL but the method of the second portlet, set with @RenderMapping(params) is never called.

Thanks in advance First portlet view.jsp:

<%@page import="java.util.List"%>
<%@page import="pl.spot.vorange.model.Project"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<div id="projectListDiv"  style="width: 100%;"></div>

<script type="text/javascript">
var pids = new Array();
var pnames = new Array();
var projectId = "${p.id}";
<%
List<Project> all = (List<Project>) request.getAttribute("all");
if(all!=null && !all.isEmpty()) {
int i = 0;
for(Project project : all) {
    out.println("pids[" + i + "]='"+project.getId()+"';\n");
    out.println("pnames[" + i + "]='"+project.getName()+"';\n");
    i++;
}
} else {
    out.println("brak projektów w zasięgu requestu");
}
%>

function createProjectList() {
var tags = "<table width='100%'>";

for(var i=0; i<pids.length; i++) {
    tags += "<tr class='projectTr'>";
    tags += "<td class='orangeArray' onClick='firePortletEvent2(" + pids[i] +  
")'> </td>";

    if(pids[i]!=projectId) {
        tags += "<td class='orangeTableItem' onClick='firePortletEvent2(" +
 pids[i] + ")'>";
    } else {
        tags += "<td class='orangeTableItemSel'  
 onClick='firePortletEvent2(" + pids[i] + ")'>";
    }

    tags += pnames[i] + "</td></tr>";
}

tags += "</table>";
el = document.getElementById("projectListDiv");
if(el!=null) {
    el.innerHTML = tags;
}
}
function firePortletEvent2(projectId) {
var url ="<portlet:renderURL />";   
prefix = "&_offer2_WAR_vorange_";
url += prefix+"a=getproject";
url += prefix+"page=expiring";
url += prefix+"tab=expiringOffers";
url += prefix+"pid="+encodeURI(projectId);
location = url;
}

createProjectList();
</script>

Clicking on one of the projects renders the URL.

Second portlet controller:

@RenderMapping(params = "a=getproject")
public String getProject(RenderResponse response, RenderRequest request) {

    String pid = request.getParameter("pid");
    Project p = null;
    if (pid != null) {
        long id = Long.parseLong(pid);
        p = projectService.searchById(id);
        request.getPortletSession().setAttribute("project", p);
    }

    p = (Project) request.getPortletSession().getAttribute("project");
    request.setAttribute("p", p);

    return "view";
}

I don't know if it's working correctly because this method is never called.

I know the code is messy but I haven't written it. I just obtained it and I must fix it.

I wouldn't be surprised if this code will never work but I have just started developing on Liferay and don't know many things.

Nav
  • 437
  • 1
  • 8
  • 16
  • 1
    Please paste the relevant code... – Sumit Desai Nov 13 '12 at 15:25
  • 1
    Are you doing also the postback to the server after changing the url? Do you need only client side communication? In that case I suggest you to take a look at the following SO answers: http://stackoverflow.com/questions/6853730/inter-portlet-communication-in-liferay and http://stackoverflow.com/questions/8135405/eventing-in-liferay-portlets/13258317#13258317 – Tony Rad Nov 13 '12 at 15:58

0 Answers0