Search code examples
javaeclipseliferayportletportal

How to send selected id in parameter using actionURL?


Here is my view.jsp:

<portlet:actionURL name="getTravelId" var="travelIdUrl">
</portlet:actionURL>
for (Travel t : list) {
    <a href="<%=travelIdUrl%>"><%=t.getId() %></a>
}

Then in the class:

 @ProcessAction(name="getTravelId")
        public void getSelectedTravelId(ActionRequest request, ActionResponse response){

        String idTravel = request.getParameter("idTravel");

        System.out.println("TRAVEL ID: " + idTravel);

    }

I tried sending the parameter like:

  <a href="<%=travelIdUrl%>?travelId="<%=t.getId()%>""><%=t.getId() %></a>

but not working.

Also tried putting the actionURL inside for, still not working

 for (Travel t : list) {
 <portlet:actionURL name="getTravelId" var="travelIdUrl">
        <portlet:param name="idTravel" value="<%t.getId()%>"/>
    </portlet:actionURL>
 <a href="<%=travelIdUrl%>"><%=t.getId() %></a>
    }

Does anyone have a solution? Thanks..


Solution

  • You were definitely on the right path using the <portlet:param> tag to add parameters to a portlet URL. Perhaps you can try using more JSTL and fewer scriptlets. Try something more like the code snippet below.

    <c:forEach items='${list}' var="travel">
        <portlet:actionURL name="getTravelId" var="travelIdUrl">
            <portlet:param name="idTravel" value="${travel.id}"/>
        </portlet:actionURL>
        <a href="${travelIdUrl}">${travel.id}</a>
    </c:forEach>