How do I know when a page refresh occurs?


I am building a wrapper around a javascript gauge component.

All is going well, but, in order to stream line processing in my paintContent I only ‘paint’ things I know have changed (see code below).

I have done this so that when I increment the gauge needle, it does not redraw the whole gauge (which causes flicker if someone is repeatedly pushing an increase button for example).

The problem is that on a page refresh, or when the user comes back to the page, the component thinks nothing has changed, therefore my GWT wrapper does not get the wrapped javascript to repaint, meaning that on first look at the page it looks great, on refreshing the page, the gauge disappears.

My question is how can I tell that the page has been refreshed? Is there an event I can hook into for this? I could then change all my fields to ‘dirty’ which will mean that the javascript code will get run and refresh the gauge.

Note that if I remove the ‘Dirty’ fields, it does work, but the gauge flashes when changing the needle value as the whole gauge is redrawn rather than just the needle.

Thanks for any help… a bit new to all this.


    public void paintContent(PaintTarget target) throws PaintException {

        // Paint any component specific content by setting attributes
        // These attributes can be read in updateFromUIDL in the widget.

    	if ((gaugeWidth != null) && gaugeWidthDirty) { 
    		target.addAttribute("gaugeWidth", gaugeWidth);
    		gaugeWidthDirty = false;
    	if ((gaugeHeight != null) && gaugeHeightDirty) { 
    		target.addAttribute("gaugeHeight", gaugeHeight);
    		gaugeHeightDirty = false;
    	if ((labelFormatPattern != null) && labelFormatPatternDirty) { 
    		target.addAttribute("labelFormatPattern", labelFormatPattern);
    		labelFormatPatternDirty = false;
    	if ((xml != null) && xmlDirty) { 
    		target.addAttribute("xml", xml);
			xmlDirty = false;
    	if (valueDirty) {
    		target.addAttribute("value", value);
    		valueDirty = false;

You can detect refreshing the browser as well as some other similar situations with PaintTarget.isFullRepaint() which I think was was introduced for Vaadin 6.7.

An alternative way of avoiding flickering is to always send the current settings to the client side implementation, where you keep track of the currently rendered values and only trigger the javascript to render the gauge again if they have changed.

Thanks very much… the first option worked, and I might have a look at the second :slight_smile:

Thanks again.

Sorry, how do you use PaintTarget in order to check for the isFullRepaint() boolean return value if you use a base UI class? Is it possible?

For example I need to check if it is the first time a UI is instantiated or it’s coming from a refresh of the browser window (F5), how can I check this using PaintTarget?