Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
L P Bharat
Vaadin Portlet - Application is not reset when page is loaded
February 14, 2012 3:24 AM
Answer

L P Bharat

Rank: Junior Member

Posts: 39

Join Date: August 20, 2008

Recent Posts

Hi,

I have created a vaadin portlet in liferay. My problem is that when user reloads the page application does not reset .

For example:
suppose I have 2 pages in liferay "PageA" and "PageB".
On PageA I have a vaadin portlet having table of employees, when any row is clicked new screen is loaded showing employee details.

Now if I go to PageB and come back to PageA (Using menu). It still shows the employee details instead of employee list.
What I need is to reset the portlet when user comes back to the page.

Please Suggest.
David H Nebinger
RE: Vaadin Portlet - Application is not reset when page is loaded
February 14, 2012 5:16 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7238

Join Date: September 1, 2006

Recent Posts

Portlets are stateful. You would need to hack this into place to make them non-stateful.
Tomek Lipski
RE: Vaadin Portlet - Application is not reset when page is loaded
February 15, 2012 2:26 AM
Answer

Tomek Lipski

Rank: Junior Member

Posts: 33

Join Date: November 17, 2010

Recent Posts

Hi,

It is a key feature (not a bug) of Vaadin applications that they persist state across page reloads by default. What you can do is subscribe for portlet render events, e.g. in init() method of your class extending com.vaadin.Application, you can add portlet listener when context is portal-related:

1
2        ApplicationContext applicationContext = getContext();
3        if (applicationContext instanceof PortletApplicationContext2) {
4            PortletApplicationContext2 portletCtx = (PortletApplicationContext2) applicationContext;
5            portletCtx.addPortletListener(this, this);
6        } else {
7            mainWindow.addComponent(new Label(getMessage("please.use.from.a.portlet")));
8        }


And then by implementing PortletApplicationContext2.PortletListener interface, you can react on render requests (which should happen only when entire portal page is rendered or portlet is added to the page and is ajaxable):

1
2public void handleRenderRequest(RenderRequest request, RenderResponse response, Window window) {
3    //... do sth
4}


You can also force restart of Vaadin application by adding ?reloadApplication parameter to the url - but such approach is more fit for development than production use.

Best regards,

Tomek Lipski
Nicolas Barbulesco
Reloading
December 5, 2012 9:30 AM
Answer

Nicolas Barbulesco

Rank: New Member

Posts: 3

Join Date: December 5, 2012

Recent Posts

Tomek Lipski:


You can also force restart of Vaadin application by adding ?reloadApplication parameter to the url - but such approach is more fit for development than production use.



Dzień dobry !

I am much interested in this, but it does not work.

I have a Vaadin portlet on Liferay 6.1, I access it by the address
1http://__MY_LOCAL_IP_ADDRESS__:8160
. I try
1http://__MY_LOCAL_IP_ADDRESS__:8160/?reloadApplication
, but this does not refresh my portlet.

Do you have a way to make this work ?

Thank you,

Nicolas
Tomek Lipski
RE: Reloading
December 5, 2012 10:27 AM
Answer

Tomek Lipski

Rank: Junior Member

Posts: 33

Join Date: November 17, 2010

Recent Posts

Nicolas Barbulesco:
Tomek Lipski:


You can also force restart of Vaadin application by adding ?reloadApplication parameter to the url - but such approach is more fit for development than production use.


I am much interested in this, but it does not work.
I have a Vaadin portlet on Liferay 6.1, I access it by the address
1http://__MY_LOCAL_IP_ADDRESS__:8160
. I try
1http://__MY_LOCAL_IP_ADDRESS__:8160/?reloadApplication
, but this does not refresh my portlet.
Do you have a way to make this work ?


Hi!

My bad, it was supposed to be ?restartApplication. Hope that helps! Also, remember to use JRebel - it really speeds up development with Vaadin.

t
Nicolas Barbulesco
Reloading the portlet...
December 6, 2012 1:58 AM
Answer

Nicolas Barbulesco

Rank: New Member

Posts: 3

Join Date: December 5, 2012

Recent Posts

Thank you Tomek, this works ! :-)

I have to manage the reloading in the Web app itself of course, and I am having more problems with your proposed solution. I have looked for a simpler solution, but I haven't found one yet. I just want a
1display()
method in addition to the
1init()
method. :-)

Regarding your context stuff, I tried it, but, when I clicked to add unimplemented methods, I got three methods for the price of one, and I don't really know what to write in them :

 1
 2
 3    @Override
 4    public void handleRenderRequest(RenderRequest request, RenderResponse response, Window window) {
 5        mainWindow.addComponent(new Label("handleRenderRequest"));
 6        System.out.println("handleRenderRequest");
 7        // TODO write here
 8    }
 9
10    @Override
11    public void handleEventRequest(EventRequest request, EventResponse response, Window window) {
12        mainWindow.addComponent(new Label("handleEventRequest"));
13        System.out.println("handleEventRequest");
14        // TODO write here
15    }
16
17    @Override
18    public void handleResourceRequest(ResourceRequest request, ResourceResponse response, Window window) {
19        mainWindow.addComponent(new Label("handleResourceRequest"));
20        System.out.println("handleResourceRequest");
21        // TODO write here
22    }


Any help would be welcome.

Have a nice day.

Nicolas
Nicolas Barbulesco
Reloading the portlet...
January 29, 2013 2:38 AM
Answer

Nicolas Barbulesco

Rank: New Member

Posts: 3

Join Date: December 5, 2012

Recent Posts

Let's try to make this work, and put the clear solution on this forum !

I had my portlet class extending com.vaadin.Application. Now, in addition, I make it implement com.vaadin.terminal.gwt.server.PortletApplicationContext2.PortletListener.

Tomek Lipski:


1
2        ApplicationContext applicationContext = getContext();
3        if (applicationContext instanceof PortletApplicationContext2) {
4            PortletApplicationContext2 portletCtx = (PortletApplicationContext2) applicationContext;
5            portletCtx.addPortletListener(this, this);
6        } else {
7            mainWindow.addComponent(new Label(getMessage("please.use.from.a.portlet")));
8        }




I have three candidates for ApplicationContext. I choose com.vaadin.service.ApplicationContext.

I had mainWindow created in init(). To make your code work, I have made the mainWindow an attribute of my portlet class :

1private Window mainWindow;


Yesterday I got a big Liferay "internal error" after all of that, so I thought it had broken everything, so I rolled back. But today I have done it again, more slowly, and... it seems to work !

When I do a soft reload, that is a reload without the "?restartApplication", the init() method does not get called, and in my console I get :

1
2
3handleResourceRequest
4handleRenderRequest
5handleResourceRequest


Why do I have 2 handleResourceRequest calls ? No idea.

The good thing is thehandleRenderRequest call. So I will write all my reloading code in it.

Nicolas
Tomek Lipski
RE: Reloading the portlet...
December 7, 2012 7:38 AM
Answer

Tomek Lipski

Rank: Junior Member

Posts: 33

Join Date: November 17, 2010

Recent Posts

Nicolas Barbulesco:
Let's try to make this work, and put the clear solution on this forum !



If you want to reset an application on every page refresh (or in some complicated cases related to page refresh), you can do it by implementing PortletApplicationContext2.PortletListener.handleRenderRequest, just like here:

https://github.com/tlipski/newsletter-for-liferay/blob/master/src/main/java/pl/net/bluesoft/rnd/newsletter/portlets/NewsletterPortletApplication.java

In the example above, on every render request we are checking portlet mode - EDIT vs VIEW and if the mode has changed, we init and display different kind of UI. Of course this code can just simply init and render gui every time.

t
Paul Butenko
RE: Reloading the portlet...
April 18, 2013 4:31 AM
Answer

Paul Butenko

Rank: Junior Member

Posts: 38

Join Date: July 1, 2010

Recent Posts

Hi,
I also used this solution but faced some problem with memory leak - on reinitialising application removed components are not collected with GC. Here is more detailed description.
Does somebody know what can be the problem?

Thanks in advance,
Paul Butenko