4

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?

jahra
  • 1,173
  • 1
  • 16
  • 41
  • Init param `config-jsp` and overriden method `ConfigurationActionImpl#render` are mutually exclusive. You don't have to implement the method, when there's `config-jsp` init param defined. Is the JSP path really correct? Check the logs again, I believe there will be sort of error - JSP compilation problem or something like that. – Tomas Pinos Oct 16 '15 at 12:57
  • There are no errors in logs. I tried different ways to provide jsp path (with config-jsp and render method). Exception throws when I remove "/" before jsp path. In other cases there is no errors in log, and different paths don't work @TomášPiňos – jahra Oct 16 '15 at 13:07
  • Try to insert some debug info into the JSP (`<% System.out.println("This is JSP"); %>`) and comment out everything else (including imports). If you see the info in the console, we can rule out the incorrect path. – Tomas Pinos Oct 16 '15 at 13:15
  • I tried you suggestion, but there are no messages in console. @TomášPiňos – jahra Oct 16 '15 at 13:22
  • I figured out the solution. The right path is "/WEB-INF/html/jsp/config.jsp", but it's very weird. Thak you for your answers @TomášPiňos – jahra Oct 16 '15 at 13:32
  • Right. That's the value you have in the init param. I summarized the findings in an answer. – Tomas Pinos Oct 16 '15 at 14:13

1 Answers1

3

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).

Tomas Pinos
  • 2,812
  • 14
  • 22