Code Monkey home page Code Monkey logo

base-starter-flow-portlet's Introduction

Vaadin Portlet Starter Project

Project to get started with a Vaadin 23.1+ application that is running inside a portlet in a Liferay 7 Portal.

Prime Vaadin subscription is required for this starter project and for all the applications using Vaadin Portlet. You also need to have Java 11 (or later) installed.

Clone the repository and import the project to the IDE of your choice as a Maven project.

The documentation for Vaadin Portlet support is available here.

Project demo

Run the following profile to automatically download and set up the Liferay bundle:

mvn clean package -Pdemo

Start the Liferay with your portlet:

mvn cargo:run

Set up Liferay manually and running the portlet

Before the portlet application can be run, it must be deployed to a Liferay:

  1. Build the whole project using mvn install -DskipTests in the root

  2. We assume Liferay is running in http://localhost:8080/, an easy way to run a local copy of Liferay is to use their official docker images. Below is an example of a docker-compose file you can use.

version: "2.2"
services:
    liferay-dev:
        image: liferay/portal:7.2.1-ga2
        environment:
            - LIFERAY_JAVASCRIPT_PERIOD_SINGLE_PERIOD_PAGE_PERIOD_APPLICATION_PERIOD_ENABLED=false
        ports:
            - 8080:8080
            - 8000:8000
        volumes:
            - ./deploy:/mnt/liferay/deploy
            - ./files:/mnt/liferay/files

The following steps describe how to set up the Liferay regardless of what way of Liferay distribution you choose: bundle or Docker image.

  1. Add the following to the end of the last line in Tomcat's setenv.sh (/var/liferay/tomcat-<version>/bin) before starting Liferay. When using the above docker-compose file place an edited copy of setenv.sh in ./files/tomcat/bin.
 -Dvaadin.portlet.static.resources.mapping=/o/vaadin-portlet-static/
  1. Download and add the Jna dependency JARs of a certain version into /var/liferay/tomcat-<version>/webapps/ROOT/WEB-INF/lib:

    How to copy these files is described here

    This is needed because Liferay uses an older version of Jna and running Vaadin Portlet in dev mode causes a conflict of dependencies used by Liferay and Vaadin License Checker (NoClassDefFound exception).

    Here is a useful docs describing how to add third-party dependency version you want.

  2. Run docker-compose up

  3. Deploy all wars: vaadin-portlet-static.war and portlet-starter.war to your docker container by copying them to ./deploy/ (the copied files should disappear when deployed).

  4. Wait for the bundles to start, then visit http://localhost:8080/. Set up a new user if you're running Liferay for the first time. Default is [email protected]/test. Log in into Liferay.

  5. The deployed portlet needs to be added to a portal page. Do this by

  • Selecting the Plus or the Pen icon near top right of the page (exact placement and look varies by Liferay version) add elements to the current page.
  • Under Widgets on the right sidebar find Vaadin Liferay Portlet category under which you will find entry for MyPortlet1, drag and drop it onto the page.
  • If at the top right of the page, in edit mode, you see a Publish button, use it to make your changes public (7.3+).

Remote debugging for Liferay

In order to remote debug your portlet under Liferay add the following to the end of the last line in Tomcat's setenv.sh (/var/liferay/tomcat-<version>/bin) before starting Liferay. When using the above docker-compose file place an edited copy of setenv.sh in ./files/tomcat/bin before docker-compose up.

 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

Remote debugging (JDWP) is now available on port 8000 (to activate in IntelliJ, choose Run -> Attach to Process...).

Production build

Before deploying your portlet for production for the first time, you will probably want to change portlet-name in portal.xml from TestPortlet1 to something else, as well as the tag returned by MyPortlet.PORTLET_TAG from portlet-content to something else (stock Pluto already contains portlets with these names). Then build the production .war:

mvn package -Pproduction

Copy both portlet-starter.war and vaadin-portlet-static.war from /target folder into the deploy folder of a Liferay container.

Portlet development in servlet mode

It is possible to develop portlets as normal single route Vaadin applications.

Note: When developing using servlet mode no Portlet specific methods can be used in the view for servlet mode.

To develop portlets in servlet mode using jetty create a Route for portlet content e.g.

package com.vaadin.starter.portlet;

import com.vaadin.flow.router.Route;

@Route("")
public class ServletDevelopment extends MyPortletContent {
}

Then run the project as mvn clean jetty:run -Pservlet

Creating a Portlet with servlet mode

To create an application that can be used both as a portlet and a servlet application you need to check at generation time the Request type.

For instance MyPortletContent could be setup as

public class MyPortletContent extends VerticalLayout {
    public MyPortletContent() {
        String message;
        if (VaadinRequest.getCurrent() instanceof PortletRequest) {
            VaadinPortlet portlet = VaadinPortlet.getCurrent();
            String name = portlet.getPortletName();
            String serverInfo = portlet.getPortletContext().getServerInfo();
            message = String
                    .format("Hello from %s running in %s!", name, serverInfo);
        } else {
            message = String
                    .format("Hello from %s running in a servlet container",
                            getClass().getSimpleName());
        }
        Button button = new Button("Click me",
                event -> Notification.show(message));
        add(button);
    }
}

Current known issues running under Liferay

See Vaadin Portlet release notes for a limitation and known issues list.

base-starter-flow-portlet's People

Contributors

caalador avatar dependabot[bot] avatar mehdi-vaadin avatar mshabarov avatar pleku avatar ujoni avatar vaadin-bot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

anil23489

base-starter-flow-portlet's Issues

Make this a "public" worthy repository

Requirements

  • User can build and deploy a Vaadin portlet to Pluto using this starter
    • documentation has copy-pasteable steps to follow
    • uses latest portlet-support snapshot

Project is not compilable for version 14.1

https://bender.vaadin.com/viewLog.html?buildId=146749&buildTypeId=Flow_StarterTests_FlowStartersItPlatform141Snapshot_PortletStarterIt

/opt/agent/work/54d731b39d1e6698/src/main/java/com/vaadin/starter/portlet/MyPortlet.java:[5,8] cannot access com.vaadin.flow.component.WebComponentExporterFactory
[10:45:35][Step 3/6]   class file for com.vaadin.flow.component.WebComponentExporterFactory not found
[10:45:35][Step 3/6] [ERROR] /opt/agent/work/54d731b39d1e6698/src/main/java/com/vaadin/starter/portlet/MyPortlet.java:[7,5] method does not override or implement a method from a supertype
[10:45:35][Step 3/6] [INFO] 2 errors 

Empty portlet content

Hello.

Thanks for your examples. Can you give me some advice, please, why when I place portlet from this example on liferay portal - portlet content is empty?

image

Using vaadin-core (free) still wants a Pro licence

I am not sure where best to ask about this.

I want to create a Vaadin (if possible) portlet (I had a couple of version 7 portlets running on Liferay 6.x some time ago).

Looking at Liferay 7.x, it seems an OSGi portlet is a no go as it is part of the commercial Vaadin offering (which is not an option in this case). The documentation talked about using a non OSGi Portlet 3.0 alternative, so this is the track that led me here.

I have cloned this repo, and in the pom.xml changed the dependancy to vaadin-core as suggested by the comment:

 <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>

So I changed the above to vaadin-core, and managed to compile and deply to pluto, but it seems to still want to go off to Vaadin servers and validate my developer pro licence. I got a trial which solved the problem, for two weeks I am guessing.

So the behaviour seems to imply that, although the comment indicates you can use the Vaadin free version, in fact you can't.

Is this correct behaviour?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.