diff options
-rw-r--r-- | uitest/src/com/vaadin/tests/minitutorials/v7b1/Addition.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b1/Addition.java b/uitest/src/com/vaadin/tests/minitutorials/v7b1/Addition.java index 7e1c9ecf2a..a91df49508 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7b1/Addition.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b1/Addition.java @@ -22,14 +22,23 @@ import com.vaadin.ui.AbstractComponent; public class Addition extends AbstractComponent { private int term1; private int term2; + private boolean needsRecalculation = false; public void setTerm1(int value1) { - this.term1 = value1; + term1 = value1; + needsRecalculation = true; + + // Mark the component as dirty to ensure beforeClientResponse will be + // invoked markAsDirty(); } public void setTerm2(int value2) { - this.term2 = value2; + term2 = value2; + needsRecalculation = true; + + // Mark the component as dirty to ensure beforeClientResponse will be + // invoked markAsDirty(); } @@ -39,7 +48,13 @@ public class Addition extends AbstractComponent { @Override public void beforeClientResponse(boolean initial) { - getState().sum = calculateSum(); + super.beforeClientResponse(initial); + if (needsRecalculation) { + needsRecalculation = false; + // This could be an expensive operation that we don't want to do + // every time setTerm1 or setTerm2 is invoked. + getState().sum = calculateSum(); + } } @Override |