Directory

← Back

Refresher

A non-visible poller component

Author

Rating

Popularity

100+

Deprecated. Use Vaadin 7 polling instead.

Because of the way Vaadin works, asynchronous UI changes made on the server side (e.g. by a long-duration data processing Thread) aren't reflected to the client side. This component makes it possible to make UI changes, even if the user doesn't start a transaction.

Sample code

public class RefresherUI extends UI {
	
	public class DatabaseListener implements RefreshListener {
		private static final long serialVersionUID = -8765221895426102605L;
		
		@Override
		public void refresh(final Refresher source) {
			if (databaseResult != null) {
				// stop polling
				removeExtension(source);
				
				// replace the "loading" with the actual fetched result
				content.setValue("Database result was: " + databaseResult);
			}
		}
	}
	
	public class DatabaseQueryProcess extends Thread {
		@Override
		public void run() {
			databaseResult = veryHugeDatabaseCalculation();
		}
		
		private String veryHugeDatabaseCalculation() {
			// faux long lasting database query
			try {
				Thread.sleep(6000);
			} catch (final InterruptedException ignore) {
				return "interrupted!";
			}
			return "huge!";
		}
	}
	
	private static final long serialVersionUID = -1744455941100836080L;
	
	private String databaseResult = null;
	private Label content;
	
	@Override
	public void init(final VaadinRequest request) {
		// present with a loading contents.
		content = new Label("please wait while the database is queried");
		addComponent(content);
		
		// the Refresher polls automatically
		final Refresher refresher = new Refresher();
		refresher.addListener(new DatabaseListener());
		addExtension(refresher);
		
		new DatabaseQueryProcess().start();
	}
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Support for Vaadin 7 Beta 11

Released
2013-01-09
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.0+
Vaadin 7.1+ in 1.2.3.7
Vaadin 6.2+ in 1.1.1
Browser
Internet Explorer
Internet Explorer
Internet Explorer
Firefox
Opera
Safari
Google Chrome
Internet Explorer
iOS Browser
Android Browser

Refresher - Vaadin Add-on Directory

A non-visible poller component Refresher - Vaadin Add-on Directory
**Deprecated. Use [Vaadin 7 polling](http://stackoverflow.com/a/24364359) instead.** Because of the way Vaadin works, asynchronous UI changes made on the server side (e.g. by a long-duration data processing Thread) aren't reflected to the client side. This component makes it possible to make UI changes, even if the user doesn't start a transaction.
Video Demo
Forum Post
Live Demo
Source Code
Chat Application Article

Refresher version 1.0.0
null

Refresher version 1.1.0
- Package name is now com.github.wolfie.refresher.* - Replaced example application with something more practical - Added a default interval of 1sec - Fixed a bug where the component would keep on refreshing even if it's disabled.

Refresher version 1.1.1
Fixed a bug where the refresher would stop working after a repaint (especially in CSSLayouts)

Refresher version 1.1.1.7
Ported to Vaadin 7

Refresher version 1.1.2.7
- Supports Vaadin 7 alpha 3 - Supports Java 1.5 - Stops refreshing if .setEnable(false) is called

Refresher version 1.1.3.7
Support for Vaadin 7.0.0 beta5

Refresher version 1.2.1.7
Support for Vaadin 7 Beta 11

Refresher version 1.2.2.7
Avoiding concurrent modification exceptions.

Refresher version 1.2.3.7
No new code, just recompiled in Java 6

Online