简体   繁体   中英

Getting response form custom @proceesAction in WebSphere Portal Portlet

i am developing a Portlet in WebSphere Portal 8 and i am having problems to get the response from a custom @processAction method, the method is called and executed, but in the jsp i cant get the data returned...

I have a jsp file wich has:

-definition of portlet actionURL...

<portlet:defineObjects/>
<portlet:actionURL var="cargarListadoConcursosURL">
       <portlet:param name="<%=ActionRequest.ACTION_NAME%>" value="cargarListadoConcursos" />
    </portlet:actionURL>

-javascript method with ajax post method:

<script type="text/javascript">
    $(document).ready(function() {
        cargarListadoConcursos();
    });

    function cargarListadoConcursos() {
        $.ajax({
            url : '<%=cargarListadoConcursosURL%>',
            type : 'POST',
            dataType : 'json',
            success : function(data) {
                alert(data);
                //do something!!!
            }
        });
    }

and my portlet class looks like:

public class ListadoConcursosPortlet extends GenericPortlet
{
   //more methods...

    @ProcessAction(name="cargarListadoConcursos")
    public void cargarListadoConcursos(ActionRequest request, ActionResponse response) throws PortletException, IOException {
        HttpServletResponse resp = PortletUtils.getHttpServletResponse(response);
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter writer = resp.getWriter();
        writer.append(gson.toJson(new ArrayList<Concurso>()));
        writer.flush();
        resp.flushBuffer();
        System.out.println("Paso por cargarListadoConcursos");
    }
}

I think that the portlet.xml its fine beacuase the jsp call the portlet cotroller (the syso appears at console)...

Well in conclution, the problems is that i cant get the Json object in my javascript called, and the alert(data) is never executed...

Thanks in advance for any tip!!!

The issue is that the page is refreshed when you it the actionURL. You need to use a Resource Serving Portlet, the serveResource method and an resourceURL which doesn't refresh the page when called.

使用serveResource()....并从jsp使用resourceURL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM