我想为 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>
配置ActionImpl
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 路径,但没有进展。我该怎么办?
最佳答案
如果配置操作类扩展 DefaultConfigurationAction
,将 JSP 路径指定为 portlet.xml 中的 init 参数就足够了(configTemplate
和 config-jsp
是同样有效的名称)。您不必覆盖 render
方法。
在您的情况下,配置操作类不扩展 DefaultConfigurationAction
,所以 init 参数是没用的。
JSP 路径必须始终从类路径根目录开始 - 即。从 /WEB-INF
开始对于放置在那里的 JSP。
见Developer's Guide有关 portlet 配置的完整描述。
您还可以使用 Spring Portlet MVC 框架(如问题所示使用)开发可配置的 portlet。这意味着要为编辑 portlet 模式 (@Controller @RequestMapping("edit")
) 创建一个专用 Controller 。使用 Spring,您可以以与 portlet View 模式相同的方式实现配置(即使用相同的 JSP 标记、表单绑定(bind)、验证以及 Spring 框架带来的所有舒适性)。
关于jsp - Liferay:创建一个 portlet 配置页面。如何提供正确的jsp路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33170762/