Question

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

Was it helpful?

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>

OTHER TIPS

what exactly did not work in your last example? I think you are mixing Java code with HTML and tags. Try this example in your JSP:

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

It creates an anchor for each item in list with given id parameter. The example uses only HTML and tags and JSP expresion language for accessing variables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top