掲示板

Can't get a very simple MVCPortlet to work

6年前 に Thomas Kellerer によって更新されました。

Can't get a very simple MVCPortlet to work

Expert 投稿: 490 参加年月日: 08/06/09 最新の投稿
I'm trying to migrate several portlets from 6.0 to 7.0 (GA4). None of them worked, so I created a very, very simple portlet to see if I got that complicated OSGi deployment right.

Unfortunately not even the most simple "Hello, World" MVCPortlets works in my environment.

This is my pom.xml
<!--?xml version="1.0" encoding="UTF-8"?-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelversion>4.0.0</modelversion>
	<groupid>com.kaa</groupid>
	<artifactid>test-portlet</artifactid>
	<version>1.0</version>
	<packaging>jar</packaging>
  <name>test-portlet</name>

	<properties>
		<project.build.sourceencoding>UTF-8</project.build.sourceencoding>
	</properties>

	<dependencies>
		<dependency>
			<groupid>com.liferay.portal</groupid>
			<artifactid>com.liferay.portal.kernel</artifactid>
			<version>2.0.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupid>com.liferay.portal</groupid>
			<artifactid>com.liferay.util.taglib</artifactid>
			<version>2.0.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupid>javax.portlet</groupid>
			<artifactid>portlet-api</artifactid>
			<version>2.0</version>
			<scope>provided</scope>
		</dependency>
    <dependency>
			<groupid>org.osgi</groupid>
			<artifactid>osgi.cmpn</artifactid>
			<version>6.0.0</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
    <finalname>my_test_portlet</finalname>
		<plugins>
      <plugin>
        <groupid>org.apache.maven.plugins</groupid>
        <artifactid>maven-compiler-plugin</artifactid>
        <version>3.6.0</version>
        <configuration>
          <source>1.8
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
        <groupid>org.apache.maven.plugins</groupid>
        <artifactid>maven-jar-plugin</artifactid>
        <version>3.0.2</version>
        <configuration>
          <archive>
            <manifestfile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestfile>
          </archive>
          <excludes>
            <exclude>**/META-INF/resources/**/.sass-cache/</exclude>
          </excludes>
        </configuration>
      </plugin>
      
      <plugin>
        <groupid>biz.aQute.bnd</groupid>
        <artifactid>bnd-maven-plugin</artifactid>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>default-bnd-process</id>
            <goals>
              <goal>bnd-process</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupid>biz.aQute.bnd</groupid>
            <artifactid>biz.aQute.bndlib</artifactid>
            <version>3.1.0</version>
          </dependency>
          <dependency>
            <groupid>com.liferay</groupid>
            <artifactid>com.liferay.ant.bnd</artifactid>
            <version>2.0.32</version>
          </dependency>
        </dependencies>
      </plugin>
      
      <plugin>
        <groupid>com.liferay</groupid>
        <artifactid>com.liferay.css.builder</artifactid>
        <version>1.0.23</version>
        <executions>
          <execution>
            <id>default-build-css</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>build-css</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <docrootdirname>src/main/resources</docrootdirname>
        </configuration>
      </plugin>
    </plugins>

	</build>
</project>


This is my bnd.bnd file:
Bundle-Name: test_portlet
Bundle-SymbolicName: com.myportlet
Bundle-Version: 1.0
ConfigurationPath: /configuration
Include-Resource: configuration=src/main/resources/configuration
-jsp: *.jsp,*.jspf
-plugin.jsp: com.liferay.ant.bnd.jsp.JspAnalyzerPlugin
-plugin.resourcebundle: com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin
-plugin.sass: com.liferay.ant.bnd.sass.SassAnalyzerPlugin
-sass: *


This is my portlet class:

@Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=Test Portlets",
        "com.liferay.portlet.instanceable=true",
        "javax.portlet.display-name=My Test Portlet",
        "javax.portlet.init-param.template-path=/",
        "javax.portlet.init-param.view-template=/hello.jsp",
        "javax.portlet.name=test_portlet",
        "javax.portlet.resource-bundle=content.Language",
        "javax.portlet.security-role-ref=user",
    },
    service = Portlet.class
)
public class TestPortlet
    extends MVCPortlet {

    public TestPortlet() {
        LogFactoryUtil.getLog(getClass()).info("*** Hello World Portlet initialized");
    }

    @Override
    public void render(RenderRequest request, RenderResponse response)
        throws PortletException, IOException {

        LogFactoryUtil.getLog(getClass()).info("*** Hello World render() called");

        super.render(request, response);
    }
}
The render() method is only there so that I could add a log output.

This is my hello.jsp located in src/main/resources/META-INF/resources
<div>
  <p>Testing, 123...</p>
</div>

The portlet gets deployed and I can add it to a page in my Liferay portal. But it does not display the actual content. Only the portlet header.

The logfile shows the log message "*** Hello World Portlet initialized" but it does not show the the "render() called" message. So why isn't the render() method called?

I also tried building the portlet using the Apache Felix BND plugin: https://svn.apache.org/repos/asf/felix/releases/maven-bundle-plugin-1.2.0/doc/maven-bundle-plugin-bnd.html but that didn't change anything

I am sure I am missing something obvious, but what?
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
It's hard to debug this from a discance. Maybe it helps if you look at this sample and compare the different settings and generated jar file?
6年前 に Dmitry Kovalev によって更新されました。

RE: Can't get a very simple MVCPortlet to work

New Member 投稿: 12 参加年月日: 15/04/01 最新の投稿
I've had some experience with migrating to 7.0 and it wasn't successful also.
I've done new app in 7.0 and copied source code from 6.2 to 7.0
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Can you share your project with us so that we can try it out locally as well?
6年前 に Thomas Kellerer によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Expert 投稿: 490 参加年月日: 08/06/09 最新の投稿
Andrew Jardine:
Can you share your project with us so that we can try it out locally as well?


I have attached a ZIP file with the project.

I tried to reduce it to the bare minimum. It is a fake "contact me" portlet, that pretends to send out an email.
So there is a view.jsp with a form. The corresponding action doesn't do anything except for logging that it was called, and it then forwards that to the "thank you" page.

The portlet deploys successfully and I can even see the configuration options in the control panel. But when I add the portlet to a page, nothing is displayed. If you check the log file, it does not even show the "render() called" message.

I have no clue what I am missing here.

I am using the Apache Felix maven plugin. But switching to the biz.aQute.bnd plugin doesn't make a difference (and the generated .jar file is identical in both cases, I checked that)

添付ファイル:

6年前 に Thomas Kellerer によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Expert 投稿: 490 参加年月日: 08/06/09 最新の投稿
This still isn't working. No errors, no warnings, nothing. Liferay simply doesn't display anything
thumbnail
6年前 に Christoph Rabel によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
You need to delete WEB-INF/web.xml, than it works.
6年前 に Thomas Kellerer によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Expert 投稿: 490 参加年月日: 08/06/09 最新の投稿
Christoph Rabel:
You need to delete WEB-INF/web.xml, than it works.
Indeed then this simple portlet works.

But I have existing Liferay 6 portlets that contain e.g. some servlet definitions (for Ajax requests) or taglib references.

What do I do with them if I am not allowed to use web.xml in a web application?
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
For Ajax requests, you mean endpoints that you want your portlet to respond to? if so, the convention is to use the serveResource method for those requirements -- is there a reason you can't use it?
6年前 に Thomas Kellerer によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Expert 投稿: 490 参加年月日: 08/06/09 最新の投稿
Andrew Jardine:
For Ajax requests, you mean endpoints that you want your portlet to respond to? if so, the convention is to use the serveResource method for those requirements -- is there a reason you can't use it?


I can probably use serveResources() instead of servlets, correct.

But I still don't know how to integrate my JSP tag library though.
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
I have not tried this personally, but you should be able to package up your taglib as a separate bundle and then set it as a dependency for your portlet. Basically, your taglib acts just as any other 3rd party taglib in this scenario so you should be able to reference it in your project dependency references the same way you do for the jstl taglibs. Again, I haven't tried it yet, but this is supposed to be one of the benefits of OSGI.
thumbnail
6年前 に Christoph Rabel によって更新されました。

RE: Can't get a very simple MVCPortlet to work

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
Well, I noticed that behavior when I tried to add my own servlet. It's not that the portlet is not working, I think it simply can't load the jsp files. But I didn't dig into it, it was not relevant for me.

You can:
- Split portlet and servlet into separate osgi bundles (Did that, works)
- Debug into MVCPortlet to find the root of the issue. Maybe it's something trivial.
- Maybe you could use GenericPortlet, I know it works, I tried it:

public class MyPortlet extends GenericPortlet {
protected void doView(...){
PrintWriter printWriter = renderResponse.getWriter();
printWriter.print("Hello World!");
}