portlet - Spring MVC Portlet 和 Liferay : No matching handler method found for portlet request actionUrl

标签 portlet spring-portlet-mvc

我正在使用 Spring MVC Portlet 开发一个 portlet 并部署在 Liferay 中。我对这个 portlet 的意图是显示一个包含一些重要信息的树。为了实现这个目标,我需要请求服务器 json 文件,其中包含填充树的信息。

jsp 页面本身加载正常。我添加了一个链接以测试我是否可以获得有效的 json。我一直在寻找帮助和文档,并在 jsp 中生成了一个友好的 url。但是当我点击链接获取 json 时,服务器抛出以下错误:

12:07:40,767 ERROR [http-bio-8080-exec-5][render_portlet_jsp:154] org.springframework.web.portlet.NoHandlerFoundException: No matching handler method found for portlet request: mode 'view', phase 'ACTION_PHASE', parameters map['action' -> array<String>['showTree']]
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)
    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:579)
    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:294)
    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:944)
    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:688)
    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:249)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)

也许我忘记了一些重要的事情。我粘贴我的代码的相关部分:

home.jsp(渲染的主页)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<body>
    <!-- Add a <div> element where the tree should appear: -->
    <h1>Liferay Spring Portlet MVC - Tree</h1>
    <p>The time on the server is ${serverTime}.</p>
    <p>Date: <input type="text" id="datepicker" /></p>
    <div id="tree"> </div>

    <portlet:actionURL var="ajaxTreeURL">
        <portlet:param name="action" value="showTree"/>
    </portlet:actionURL>
    <a href="<%= ajaxTreeURL.toString() %>" > Go </a>
</body>
</html>

HomeController.java(渲染页面并处理请求)

public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private ExperimentService experimentService;
    /**
     * Simply selects the home view to render by returning its name.
     */
    @RenderMapping
    public String home(Locale locale, Model model) {
        logger.info("Welcome home! the client locale is "+ locale.toString());

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

        String formattedDate = dateFormat.format(date);

        model.addAttribute("serverTime", formattedDate);

        experimentService.getExperiments();

        return "home";
    }

    @RequestMapping(params= {"action=showTree"})
     public void showTreeHandler(ResourceRequest request, ResourceResponse response, Model model) throws Exception {
        OutputStream outStream = response.getPortletOutputStream();
        StringBuffer buffer = new StringBuffer();
        Map<String, String> testMap = new HashMap<String, String>();
        testMap.put("foo", "bar");
        String test = new JSONObject(testMap).toString();
        buffer.append(test);
        outStream.write(buffer.toString().getBytes());
     }
} String home(Locale locale, Model model) {
    logger.info("Welcome home! the client locale is "+ locale.toString());

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    experimentService.getExperiments();

    return "home";
}

@RequestMapping(params= {"action=showTree"})
 public void showTreeHandler(ResourceRequest request, ResourceResponse response, Model model) throws Exception {
    OutputStream outStream = response.getPortletOutputStream();
    StringBuffer buffer = new StringBuffer();
    Map<String, String> testMap = new HashMap<String, String>();
    testMap.put("foo", "bar");
    String test = new JSONObject(testMap).toString();
    buffer.append(test);
    outStream.write(buffer.toString().getBytes());
 }
}

我添加了一些额外的配置文件 (portlet.xml):

<?xml version="1.0"?>

<portlet-app
    version="2.0"
    xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
>
    <portlet>
        <portlet-name>liferay-spring-mvc</portlet-name>
        <display-name>Liferay Spring MVC Portlet</display-name>
        <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
        <init-param>
            <name>contextConfigLocation</name>
            <value>/WEB-INF/spring/context-portlet.xml</value>
        </init-param>
        <init-param>
            <name>viewRendererUrl</name>
            <value>/mappingUrls</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>view</portlet-mode>
        </supports>
        <portlet-info>
            <title>Liferay Spring MVC Portlet</title>
            <short-title>Liferay Spring MVC Portlet</short-title>
            <keywords>liferay spring mvc portlet</keywords>
        </portlet-info>
        <security-role-ref>
            <role-name>administrator</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>guest</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>power-user</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>user</role-name>
        </security-role-ref>
    </portlet>
</portlet-app>

context-portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

     <context:annotation-config />
    <!-- Autodetect annotated controllers -->
    <context:component-scan base-package="es.unican.meteo" />

    <bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping" />  

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

有人可以帮我解决这个问题吗?

最佳答案

使用

<portlet:resourceURL var="ajaxTreeURL">
        <portlet:param name="action" value="showTree"/>
</portlet:resourceURL>

代替

<portlet:actionURL var="ajaxTreeURL">
    <portlet:param name="action" value="showTree"/>
</portlet:actionURL>

关于portlet - Spring MVC Portlet 和 Liferay : No matching handler method found for portlet request actionUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18510905/

相关文章:

java - Liferay 的 portlet 名称是如何生成的?

oracle - Liferay portlet 非liferay JNDI 数据源null

eclipse - 使用 eclipse 在 liferay 中创建自己的 portlet 的教程

java - 在 Liferay 5.2 下运行 Coldfusion 9 以服务 portlet 时出错

java - 如何设置liferay资源发布者过滤url提供的所有标签

java - WebLogic 10.3.7 文件上传返回 "Error creating bean with name ' portletMultipartResolver'"

java - 我何时以及为什么应该使用 portlet

javascript - Liferay - 如何从 @ResourceMapping 带注释的方法渲染 JSP。通过 AJAX 从 JS 文件调用此方法

java - Spring MVC 和 Liferay - 资源映射问题