Search code examples
javajsparraylistliferay

Display Arraylist on jsp page


I am trying to display the following ArrayList in the .jsp page shown but I can't seem to see any values once I run my portlet, where is the problem?

code.java

 public class TestPortlet extends MVCPortlet {
    public void displayProcess(ActionRequest request, ActionResponse response) {
        ArrayList<String> process = new ArrayList<>();
        process.add("a");
        process.add("b");
        process.add("c");
        process.add("d");
        process.add("e");

        request.setAttribute("processName", process);
    }
}

The jsp page is as shown:

<%@ include file="/init.jsp"%>

<jsp:useBean id="processName" class="java.util.ArrayList" scope="request" />

<aui:select id="process" name="processitems">
    <c:forEach items="${processName}" var="process">
        <aui:option value="${process}">
            ${process}
        </aui:option>
    </c:forEach>
</aui:select>

Any help would be much appreciated.


Solution

  • I found the solution:

    I was to use:

    public void displayProcess(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
    

    instead of

     public void displayProcess(ActionRequest request, ActionResponse response) {
    

    and at the bottom of my method the following:

    renderRequest.setAttribute("process", process); 
        super.render(renderRequest, renderResponse);
    

    On the jsp page, at the topmost point; receive the ArrayList that you are passing as:

    <% ArrayList<String> process = (ArrayList) request.getAttribute("process"); %>
    

    .

    The results are as follows:

    ArrayList on jsp, liferay