Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

(SOLVED) Mixing Vaadin with JSP, while doing portlet 2.0?

Bo Maryniuk
1 decade ago May 23, 2010 1:46pm
Marc Englund
1 decade ago May 25, 2010 12:16pm
Henri Sara
1 decade ago May 25, 2010 12:50pm
Bo Maryniuk
1 decade ago May 26, 2010 2:46am

Marc, Henri,
thanks a lot! That's exactly what I am looking for — I just didn't see this demo and just had no idea these classes exists. :*) In fact, Henri, it seems like not really needed to make all these checks since getting a portlet context works fine for generic portlets. Here is a whole code together that works for me at least on a Liferay or/and Sun Webspace (well, religion does not allows me to try this on JBoss as well as class names are quite different, LOL):

public class VaadinizedPortlet extends AbstractApplicationPortlet {
    @Override
    protected void writeAjaxPage(RenderRequest request,
                                 RenderResponse response,
                                 Window window,
                                 Application application)
            throws IOException,
                   MalformedURLException,
                   PortletException {

        if (PortletMode.VIEW.equals(request.getPortletMode())) {
            this.getPortletContext().getRequestDispatcher("/WEB-INF/portlet_view.jsp").include(request, response);
        } else {
            super.writeAjaxPage(request, response, window, application);
        }
    }

    @Override
    protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
        return VeryComplexVaadinGUIApplicationForSetupVaadinizedPortlet.class;
    }
}

Also, some changes to go to portlet.xml, something like:

<portlet>
    <portlet-class>foo.bar.VaadinizedPortlet</portlet-class>
    <init-param>
        <name>application</name>
        <value>foo.bar.VeryComplexVaadinGUIApplicationForSetupVaadinizedPortlet</value>
    </init-param>

    ....

</portlet>

Many thanks, guys! Would be nice if this part appear in the Book of Vaadin somewhere?

Update. It is also still nice to mention how to switch between the modes, in case if you want it even more flexible, e.g. your view portlet mode turns to be a Vaadin, once you have different roles etc. (well, nobody knows, just in case). So in that case, I do the following:

interface FoobarInterface {
    public FoobarInterface setSpecificMode(int mode);
}

This interface for com.vaadin.ui.Window bring together. Then:

public class PureVaadinApplication extends Application {
    public static final int VIEW_MODE = 0;
    public static final int EDIT_MODE = 1;
    public static final int PIZZA_MODE = 2;
    public static final int KARJALANPIIRAKKA_MODE = 3;

    private FoobarInterface viewWindow;
    private FoobarInterface cuisineWindow;

    @Override
    public void init() {
        this.cuisineWindow = new CuisineWindowImplementation();
        this.viewWindow = new viewWindowImplementation();
        setMainWindow(this.viewWindow);
    }

    public void setApplicationMode(int mode) {
        this.setMainWindow(mode == PureVaadinApplication.VIEW_MODE 
                           ? this.mainWindow : this.cuisineWindow.setSpecificMode(mode));
    }
}

And since now, somewhere in the "writeAjaxPage(..........)" method right before "super.writeAjaxPage" (see the first source example) do something like:

((PureVaadinApplication) application)
      .setApplicationMode(PortletMode.VIEW.equals(request.getPortletMode())
             ? PureVaadinApplication.VIEW_MODE       
             : PureVaadinApplication.KARJALANPIIRAKKA_MODE); // Tasty one, BTW :)

In fact, PortletListener won't be really handled here, since AbstractApplicationPortlet is just a GenericPortlet++.

HTH.

Last updated on May, 26th 2010
Henri Sara
1 decade ago May 28, 2010 7:27am