0
votes

I am currently trying to use Freemarker instead of JSP for my Portlet but im not sure how. I tried to set up my project but im not sure what im missing, if my setup is even remotely correct. How do I support freemarker in my vue project?

When deploying the module, I get the following errors:

 Unresolved requirement: Import-Package: com.liferay.util.bridges.freemarker; version="[7.0.0,8.0.0)"_ [Sanitized]

Using MVCPortlet instead of FreeMarkerPortlet fixes the above issue but then I get:

Path /view.ftl is not accessible by portlet vue 

Now I tried /template/view.ftl but that doesnt work either. To be honest im currently a bit lost and would appreciate some insight on how this works.

This is where my .ftl files are:

resource
  -- content
  -- META-INF.resources
  -- templates
     -- init.ftl
     -- vue.ftl

Init.ftl

<#assign aui = PortletJspTagLibs["/META-INF/liferay-aui.tld"] />
<#assign liferay_portlet = PortletJspTagLibs["/META-INF/liferay-portlet-ext.tld"] />
<#assign liferay_security = PortletJspTagLibs["/META-INF/liferay-security.tld"] />
<#assign liferay_theme = PortletJspTagLibs["/META-INF/liferay-theme.tld"] />
<#assign liferay_ui = PortletJspTagLibs["/META-INF/liferay-ui.tld"] />
<#assign liferay_util = PortletJspTagLibs["/META-INF/liferay-util.tld"] />
<#assign portlet = PortletJspTagLibs["/META-INF/liferay-portlet.tld"] />

<@liferay_theme["defineObjects"] />

<@portlet["defineObjects"] />

view.ftl

<#include "init.ftl">

<@liferay_ui["message"] key="free.caption" />

<script src="${renderRequest.getAttribute("main")}"></script>

My java portlet class

package vue.portlet;

import com.liferay.util.bridges.freemarker.FreeMarkerPortlet;
import vue.constants.VuePortletKeys;

import com.liferay.frontend.js.loader.modules.extender.npm.NPMResolver;

import java.io.IOException;

import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;


@Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=category.sample",
        "com.liferay.portlet.instanceable=true",
        "javax.portlet.init-param.template-path=/",
        "javax.portlet.init-param.view-template=/view.ftl",
        "javax.portlet.name=" + VuePortletKeys.Vue,
        "javax.portlet.resource-bundle=content.Language",
        "javax.portlet.security-role-ref=power-user,user"
    },
    service = Portlet.class
)

public class VuePortlet extends FreeMarkerPortlet {
    @Override
    public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {

        renderRequest.setAttribute("main", _npmResolver.resolveModuleName("vue") + " as main");

        super.doView(renderRequest, renderResponse);
    }

    @Reference
    private NPMResolver _npmResolver;
}

My build.gradle

dependencies {
    compileOnly group: "com.liferay", name: "com.liferay.frontend.js.loader.modules.extender.api"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.util.freemarker.contributor"
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.bridges"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib"
    compileOnly group: "javax.portlet", name: "portlet-api"
    compileOnly group: "javax.servlet", name: "javax.servlet-api"
    compileOnly group: "org.osgi", name: "osgi.cmpn"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"

    cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2"
}
1

1 Answers

0
votes

To fix this, when building the plugin, the version of "com.liferay.portal.kernel" dependency must be raised to the actual version of the Liferay bundle in which you want to work on