Need clarification on Vaadin application and a liferay portlet

HI,

I need some clarifications on the mapping between Liferay portlet and Vaading application.

This is how I am doing it right now, but am not sure if it is the right way:

  1. Define the vaadin application in web.xml

    MyVaadinApp1
    com.vaadin.terminal.gwt.server.ApplicationServlet


    Vaadin application class to start
    application
    com.my.MyVaadinApp1

  2. Define the portlet in portlet.xml

    My Portlet1
    My Portlet1

     <portlet-class>com.vaadin.terminal.gwt.server.ApplicationPortlet2</portlet-class>
     <init-param>
         <name>application</name>
         <value>com.my.MyVaadinApp1</value>
     </init-param>
    


Is the mapping one to one, ie for each liferay portlet there should be one vaadin application?


Whats the purpose of defining the servlet entry? Dont see it being used anywhere. I Did it so, because I saw this in the examples war


If I create multiple apps and portlets in a war, I get “Vaadin is running in DEBUG MODE.” for each Vaadin portlet running on the page. What does this mean? Is Vaddin runtime getting loaded for each application?

I went through the docs and forums, but didnt find answers to my question.

Any insight/help will be deeply appreciated.

Each Liferay Vaadin portlet should use one Vaadin application class, but one application class can be used from several different portlets. This might be useful e.g. to give the portlets different init parameters to configure functionality.

When you are using Portlet 2.0 (JSR-286), the servlet (and indeed the whole web.xml file in many cases) is not needed for the operation of the portlet, but it is present in many demos and generated projects to enable testing an application outside a portlet container.

For the “DEBUG MODE” message, you can define the (portlet or servlet, depending on the deployment) init parameter “productionMode” with the value “true”. This disables some developer-oriented functionality such as some client side logging to a debug console or FireBug.

The Vaadin client side engine (widgetset, which is a GWT module) is loaded once per page.
On the server side, the servlet or portlet prints out the debug mode message when it is initialized, and at least Liferay initializes an instance of the portlet e.g. when a WAR is deployed.

EDIT: Added details to the first part of the answer.

Thanks for your reply Henri.

I am not sure I understand you. Say, I have two functionally different portlets [PA & PB]
showing on the same page, then as per your note, both can be set to use the same application class in the portlet.xml init param? Wont the same init method in the Application class be called for those portlets? How will they then get their own views or instance variable? How will state or session information be shared between the two portlets? Is there a vaadin specific pattern to do this?

Also, is there any advantage in using the same Vaadin application class for multiple portlets? Or, conversely is there any negative impact [memory, processing etc]
in using multiple vaadin applications?

I am not sure I understand you. Say, I have two functionally different portlets [PA & PB]
showing on the same page, then as per your note, both can be set to use the same application class in the portlet.xml init param? Wont the same init method in the Application class be called for those portlets? How will they then get their own views or instance variable? How will state or session information be shared between the two portlets? Is there a vaadin specific pattern to do this?

Also, is there any advantage in using the same Vaadin application class for multiple portlets? Or, conversely is there any negative impact [memory, processing etc]
in using multiple vaadin applications?
[/quote]

Normally, you should use separate applications for different portlets. You can deploy multiple portlets running different applications in the same WAR (in which case some session management etc. is shared) or in separate WARs - the best approach depends on how the portlets are inter-related, how they communicate between each other, how you want to manage deployments etc.

Using the same application class in multiple portlet declarations is more of a special case, but it is possible (for JSR-286 portlets, the default) if you need exactly the same functionality with slight configuration differences in different locations (typically on different pages). You can then use e.g. portlet init parameters to configure the portlets differently.

As for resource usage, from the point of view of Vaadin, the overhead of using multiple smaller applications is small. If you are pushing things to the extreme, you might want to profile how your own application behaves - often, other duplication than that caused by the internal mechanisms of Vaadin is much more significant. Otherwise, I would just go with what is a “natural” separation of functionality.

That was a very helpful explanation. I have created an application for each portlet.
However, they are not behaving as expected.

I have multiple pages in Liferay and multiple vaadin portlets on each pages. I wish to redirect to Page B upon an action on a portlet on Page A.

The portlet on Page A is setting some session information that needs to be retrieved by another portlet on Page B. Now this all works well if I just use tradition portlets[ie no vaadin]
. But with Vaadin the session data doesn’t seem to be getting shared across applications.

I am setting some session attributes like so:
PortletApplicationContext2 ctx = (PortletApplicationContext2) getApplication().getContext();
ctx.getPortletSession().setAttribute(“user”, email.getValue());

Redirecting like so:
getWindow().open(new ExternalResource(redirectURL));

The redirect happens but the “user” value is not available when I try to get it like so:
PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext();
Label label = new Label("Conversation for "
+ ctx.getPortletSession().getAttribute(“user”));

the getAttribute returns NULL

Am I trying to do something weird? Is there another way to share data across vaadin portlets?

Answering my own questions:

The answer lies in:


  1. Henri’s previous post
    : http://vaadin.com/forum/-/message_boards/message/225921?_19_redirect=%2Fforum%2F-%2Fmessage_boards%2Fsearch%3F_19_redirect%3D%252Fforum%252F-%252Fmessage_boards%26_19_breadcrumbsCategoryId%3D0%26_19_searchCategoryIds%3D0%26_19_keywords%3DIPC


  2. Portlet 2.0 documentation
    : http://developers.sun.com/portalserver/reference/techart/jsr286/jsr286_3.html