Fórumok

Vaadin Portlet - Application is not reset when page is loaded

thumbnail
L P Bharat, módosítva 12 év-val korábban

Vaadin Portlet - Application is not reset when page is loaded

Junior Member Bejegyzések: 39 Csatlakozás dátuma: 2008.08.20. Legújabb bejegyzések
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.
thumbnail
David H Nebinger, módosítva 12 év-val korábban

RE: Vaadin Portlet - Application is not reset when page is loaded

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Portlets are stateful. You would need to hack this into place to make them non-stateful.
Tomek Lipski, módosítva 12 év-val korábban

RE: Vaadin Portlet - Application is not reset when page is loaded

Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2010.11.17. Legújabb bejegyzések
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:


		ApplicationContext applicationContext = getContext();
		if (applicationContext instanceof PortletApplicationContext2) {
			PortletApplicationContext2 portletCtx = (PortletApplicationContext2) applicationContext;
			portletCtx.addPortletListener(this, this);
		} else {
			mainWindow.addComponent(new Label(getMessage("please.use.from.a.portlet")));
		}


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):


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


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, módosítva 11 év-val korábban

Reloading

New Member Bejegyzések: 3 Csatlakozás dátuma: 2012.12.05. Legújabb bejegyzések
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
http://__MY_LOCAL_IP_ADDRESS__:8160
. I try
http://__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, módosítva 11 év-val korábban

RE: Reloading

Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2010.11.17. Legújabb bejegyzések
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
http://__MY_LOCAL_IP_ADDRESS__:8160
. I try
http://__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, módosítva 11 év-val korábban

Reloading the portlet...

New Member Bejegyzések: 3 Csatlakozás dátuma: 2012.12.05. Legújabb bejegyzések
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
display()
method in addition to the
init()
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 :



	@Override
	public void handleRenderRequest(RenderRequest request, RenderResponse response, Window window) {
		mainWindow.addComponent(new Label("handleRenderRequest"));
		System.out.println("handleRenderRequest");
		// TODO write here
	}

	@Override
	public void handleEventRequest(EventRequest request, EventResponse response, Window window) {
		mainWindow.addComponent(new Label("handleEventRequest"));
		System.out.println("handleEventRequest");
		// TODO write here
	}

	@Override
	public void handleResourceRequest(ResourceRequest request, ResourceResponse response, Window window) {
		mainWindow.addComponent(new Label("handleResourceRequest"));
		System.out.println("handleResourceRequest");
		// TODO write here
	}



Any help would be welcome.

Have a nice day.

Nicolas
Nicolas Barbulesco, módosítva 11 év-val korábban

Reloading the portlet...

New Member Bejegyzések: 3 Csatlakozás dátuma: 2012.12.05. Legújabb bejegyzések
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:



		ApplicationContext applicationContext = getContext();
		if (applicationContext instanceof PortletApplicationContext2) {
			PortletApplicationContext2 portletCtx = (PortletApplicationContext2) applicationContext;
			portletCtx.addPortletListener(this, this);
		} else {
			mainWindow.addComponent(new Label(getMessage("please.use.from.a.portlet")));
		}




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 :

private 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 :



handleResourceRequest
handleRenderRequest
handleResourceRequest



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, módosítva 11 év-val korábban

RE: Reloading the portlet...

Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2010.11.17. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Reloading the portlet...

Junior Member Bejegyzések: 38 Csatlakozás dátuma: 2010.07.02. Legújabb bejegyzések
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