jspliferayliferay-6portletspring-portlet-mvc

Liferay: creating a portlet configuration page. How to provide correct jsp path?


I want to create a configuration page for a liferay portlet.

Some code from 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>

When I run It, I have a tab in configuration options (render method works, I see message "RENDER CALL" in console), but my jsp is not shown, without errors and warnings. I tried different ways to provide jsp paths, but without progress. What should I do?


Solution

  • If the configuration action class extends DefaultConfigurationAction, it is enough to specify the JSP path as init param in portlet.xml (configTemplate and config-jsp are equally valid names). You don't have to override render method.

    In your case, the configuration action class doesn't extend DefaultConfigurationAction, so the init param is useless.

    The JSP path must always start on the classpath root - ie. start with /WEB-INF for JSPs placed there.

    See the Developer's Guide for complete description of portlet configurations.

    You can also develop configurable portlets with Spring Portlet MVC framework (which you use as the question suggests). That means to create a dedicated controller for edit portlet mode (@Controller @RequestMapping("edit")). With Spring, you could implement the configuration in the same manner as the portlet view mode (ie. with the same JSP tags, form binding, validation and all the comfort that Spring framework brings).