Skip to content

Pluto Portal

caalador edited this page Aug 28, 2019 · 4 revisions

Running Vaadin Portlets in Pluto portal

Download Apache Pluto portal from https://portals.apache.org/pluto/download.html and unzip.

To run Vaadin Portlets in Pluto portal you need to build the project with mvn package using the goals vaadin:prepare-frontend and vaadin:build-frontend.

After the build has finished, copy the files in target/classes/META-INF/VAADIN/build/ to Pluto tomcat ROOT folder e.g. pluto-3.0.0/webapps/ROOT/VAADIN/build/

Next you need to unzip flow-client.jar from target/[war_name]/lib/flow-client-2.1.portal-SNAPSHOT.jar and copy the files in VAADIN/static/client to tomcat ROOT e.g. pluto-3.0.0/webapps/ROOT/VAADIN/static/client.

Then just copy the portlet war file to tomcat webapps folder. e.g. pluto-3.0.0/webapps/

Start tomcat and when the server has full starter head to http://127.0.0.1:8080/pluto/portal/Pluto%20Admin

To add your portlet to a portal page:

  • In Pluto Page Administrator plugin under Portal Pages select portal page from the Select...
  • Search Portlet Applications for war_name, then select your portlet and click Add Portlet. This will add it to the selected Portal Page.

For a sample portlet see portlet-integration-tests

Simple portlet parts

To create a simple Vaadin Portlet you need 3 parts.

  1. Component
  2. VaadinPortlet
  3. WebComponentExporter
  4. portlet.xml

Component

The Vaadin Component class is the view that is shown as the portlet. e.g.

public class MainView extends VerticalLayout {

    public MainView() {
        VaadinPortlet portlet = VaadinPortlet.getCurrent();
        String name = portlet.getPortletName();
        String serverInfo = portlet.getPortletContext().getServerInfo();
        Button button = new Button("Click me", event -> Notification.show(
                "Hello from " + name + " running in " + serverInfo + "!"));
        add(button);
    }
}

VaadinPortlet

The VaadinPortlet is the class that is linked as your portlet through the portlet.xml

e.g.

public class MyPortlet extends VaadinPortlet {
}

If having multiple portlets in the same package the VaadinPortlet should define the getMainComponentTag() method

WebComponentExporter

The WebComponentExporter is used to create the portlet data for the client side as well as handling communications.

/**
 * This class defines a tag which is internally used to render the portlet.
 * Should be automated later on.
 */
@Theme(value = Lumo.class)
public class PortletContentExporter extends WebComponentExporter<MainView> {
    public PortletContentExporter() {
        super("my-portlet");
    }

    @Override
    protected void configureInstance(WebComponent<MainView> webComponent,
            MainView component) {

    }

}

portlet.xml

In this file you define the portlet class and features. The file should be in webapp/WEB-INF/portlet.xml

<?xml version="1.0"?>

<portlet-app version="2.0"
             xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
    <portlet>
        <portlet-name>myportlet1</portlet-name>
        <display-name>Flow Test Portlet</display-name>
        <portlet-class>com.vaadin.flow.portal.MyPortlet</portlet-class>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>
        <portlet-info>
            <title>Flow Test Portlet - myportlet1</title>
            <short-title>Flow myportlet1</short-title>
            <keywords></keywords>
        </portlet-info>
        <security-role-ref>
            <role-name>administrator</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>guest</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>power-user</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>user</role-name>
        </security-role-ref>
    </portlet>
</portlet-app>