Liferay:创建portlet配置页面。如何提供正确的jsp路径?

时间:2015-10-16 12:40:48

标签: jsp liferay liferay-6 portlet spring-portlet-mvc

我想为liferay portlet创建配置页。

portlet.xml中的一些代码

<portlet-name>example-config</portlet-name>
    <display-name>example-to-delete</display-name>
    <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
    <init-param>
        <name>contextConfigLocation</name>
        <value>/WEB-INF/spring-context/portlet/example-config-portlet.xml</value>
    </init-param>
    <init-param>
        <name>config-jsp</name>
        <value>/WEB-INF/html/jsp/config.jsp</value>
    </init-param>

ConfigurationActionImpl

public class ConfigurationActionImpl implements ConfigurationAction {

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
                          ActionResponse actionResponse) throws Exception {

}

@Override
public String render(PortletConfig portletConfig, RenderRequest renderRequest,
                     RenderResponse renderResponse) throws Exception {
    System.out.println("RENDER CALL");
    return "/html/jsp/config.jsp";
}
}

的liferay-portlet.xml中

<portlet>
    <portlet-name>example-to-delete</portlet-name>
    <icon>/icon.png</icon>
    <configuration-action-class>by.example.ConfigurationActionImpl</configuration-action-class>
    <instanceable>false</instanceable>      
</portlet>

当我运行它时,我在配置选项中有一个选项卡(渲染方法有效,我在控制台中看到消息“RENDER CALL”),但我的jsp没有显示,没有错误和警告。我尝试了不同的方法来提供jsp路径,但没有进展。我该怎么办?

1 个答案:

答案 0 :(得分:3)

如果配置操作类扩展DefaultConfigurationAction,则将JSP路径指定为portlet.xml中的init param就足够了(configTemplateconfig-jsp是同等有效的名称)。您不必覆盖render方法。

在您的情况下,配置操作类不会扩展DefaultConfigurationAction,因此init参数无用。

JSP路径必须始终从类路径根开始 - 即。对于放置在那里的JSP,以/WEB-INF开头。

有关portlet配置的完整说明,请参阅Developer's Guide

您还可以使用Spring Portlet MVC框架(您可以使用问题建议)开发可配置的portlet。这意味着要为编辑portlet模式(@Controller @RequestMapping("edit"))创建专用控制器。使用Spring,您可以以与portlet视图模式相同的方式实现配置(即,使用相同的JSP标记,表单绑定,验证以及Spring框架带来的所有舒适性)。