2015-10-16 74 views
4

我想为liferay portlet创建一个配置页面。Liferay:创建一个portlet配置页面。如何提供正确的jsp路径?

从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路径,但没有进展。我该怎么办?

+0

Init param'config-jsp'和overriden方法'ConfigurationActionImpl#render'是互斥的。当定义了“config-jsp”init参数时,您不必实现该方法。 JSP路径是否正确?再次检查日志,我相信会有一些错误 - JSP编译问题或类似的东西。 –

+0

日志中没有错误。我尝试了不同的方式来提供jsp路径(使用config-jsp和render方法)。当我在jsp路径前删除“/”时抛出异常。在其他情况下,日志中没有错误,并且不同的路径不起作用@TomášPiňos – jahra

+0

尝试在JSP中插入一些调试信息('<%System.out.println(“This is JSP”);%>')并评论一切(包括进口)。如果您在控制台中看到信息,我们可以排除不正确的路径。 –

回答

3

如果配置操作类扩展为DefaultConfigurationAction,那么将JSP路径指定为portlet.xml中的初始参数就足够了(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框架带来的所有舒适性)。