webExplorer
webExplorer

Reputation: 1025

Not able to call processAction of Portlet

My game.jsp code -

<%@page import="java.io.Console"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<portlet:defineObjects />


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

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

<form id="gameForm" action="${sampleActionUrl}">
    <div onclick="updateGames()">CLICK HERE</div>
</form>

My Portlet Code -

package com.home;

import java.io.IOException;

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");
        System.out.println("Game.doView() >> rendering");
        rd.include(request, response);
    }

    @Override
    public void processAction(ActionRequest request, ActionResponse response)
            throws PortletException, IOException {
        System.out.println("Game.processAction() >> processAction");


    } 
 }

When the Form is submitted on click of the div. doView gets called for rendering the portlet, but not the processAction.

Is there anything I am missing?

Upvotes: 1

Views: 1360

Answers (2)

Gautam
Gautam

Reputation: 3386

Please use below code and give a try

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

<form id="gameForm" action="<%=sampleActionUrl.toString()%>" method="post">
    <input type="hidden" id="env" name="env"/>
    <div onclick="updateGames()">CLICK HERE</div>
</form>

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

If you are not using JSTL then you can use <%=sampleActionUrl.toString()%> instead of ${sampleActionUrl}

update remove below piece of code

@RenderMode(name = "EDIT")

Upvotes: 1

rp.
rp.

Reputation: 3465

First check that you have set the following in WEB-INF\portlet.xml

<portlet>

    ...

    <portlet-class>com.home.Game</portlet-class>

    ...

</portlet>

Upvotes: 0

Related Questions