简体   繁体   English

在WebSphere Portal Portlet中获取响应表单定制@proceesAction

[英]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... 我正在WebSphere Portal 8中开发Portlet,并且在从自定义@processAction方法获取响应时遇到问题,该方法被调用并执行,但是在jsp中,我无法获取返回的数据...

I have a jsp file wich has: 我有一个jsp文件,它具有:

-definition of portlet actionURL... -portlet actionURL的定义...

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

-javascript method with ajax post method: -javascript方法和ajax post方法:

<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: 我的portlet类如下所示:

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)... 我认为portlet.xml很好,因为jsp调用了portlet cotroller(syso出现在控制台上)...

Well in conclution, the problems is that i cant get the Json object in my javascript called, and the alert(data) is never executed... 好吧,结论是,问题是我无法在我的JavaScript中获得Json对象,并且永远不会执行alert(data)...

Thanks in advance for any tip!!! 在此先感谢您的提示!!!

The issue is that the page is refreshed when you it the actionURL. 问题是当您访问actionURL时页面会刷新。 You need to use a Resource Serving Portlet, the serveResource method and an resourceURL which doesn't refresh the page when called. 您需要使用Resource Serving Portlet,serveResource方法和resourceURL,它们在被调用时不会刷新页面。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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