Question

JSP CODE

<script>
    function updateGames() {
        document.getElementById("envSelected").value = "DEV";
        document.getElementById("gameForm").submit();
    }
</script>

<portlet:actionURL name="sampleActionUrl" var="sampleActionUrl">
</portlet:actionURL>

<form id="gameForm" action="${sampleActionUrl}" method="POST">
    <input type="hidden" id="envSelected" name="envSelected">
</form>
<div onClick="updateGames()">CLICK HERE </div>

After clicking the div, the control is transferred to the java portlet code (processAction())

package com.home;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.RenderMode;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class Game extends GenericPortlet {

    @Override
    @RenderMode(name = "VIEW")
    protected void doView(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        response.setContentType(request.getResponseContentType());
        PortletContext context = getPortletContext();
        PortletRequestDispatcher rd = context
                .getRequestDispatcher("/WEB-INF/jsp/game.jsp");
        String env = request.getParameter("envSelected");
        System.out.println("Game.doView() >> rendering with env : " + env);
        rd.include(request, response);
    }

    @Override
    public void processAction(ActionRequest request, ActionResponse response)
            throws PortletException, IOException {
        String env = request.getParameter("envSelected");
        System.out.println("Game.processAction() >> processAction for envSelected: " + env);
    }
}

I tried to print the value of the parameter I had set in the jsp code. It is printed as null.

Can someone please guide me what I might be missing here?

Was it helpful?

Solution

I suspect it's something to do with naming-spacing parameters.

JSR 286 compliant namespace parameter

If that doesn't help you, trying printing out all the parameters on the request to see if your parameter is there under a name you're not expecting.

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