PDA

View Full Version : Slider.setValue does not seem to set the value?



Kennard Consulting
18 Aug 2009, 1:09 AM
I'm having some difficultly with the Slider.setValue method, and upon closer inspection I'm unsure how it's meant to work. The code says...



if (this.value != value) {
SliderEvent se = new SliderEvent(this);
se.setOldValue(this.value);
se.setNewValue(value);
if (supressEvent || fireEvent(Events.BeforeChange, se)) {
this.value = value;
if (rendered) {
moveThumb(translateValue(value));
if (useTip) {
thumb.setToolTip(getToolTipConfig(value));
}
}
if (!supressEvent) {
fireEvent(Events.Change, se);
}
}
}



It appears the last code block, the one that says 'if (!suppressEvent)' is incorrectly nested.


If suppressEvent is false, and fireEvent(Events.BeforeChange, se) is also false, then the code this.value = value will never get executed, nor will the fireEvent ever get called. So therefore the value will never be set.


Am I reading this correctly? I tried the following test case (as a GWTTestCase) and it failed:



Slider slider = new Slider();
slider.setValue( 2, true );
assertTrue( 2 == slider.getValue() );


So did this:



Slider slider = new Slider();
slider.setValue( 2 );
assertTrue( 2 == slider.getValue() );


I probably need to use a Timer for that last one (to give the event time to fire), but I tried that it still didn't seem to work?

I apologise for being dumb!


Regards,


Richard.

sven
18 Aug 2009, 7:05 AM
The method works correct. Please read the bugforum guidelines and post a testcase for this that demonstrates the issue. Moving this to the help forum for now.

sven
18 Aug 2009, 7:35 AM
If suppressEvent is false, and fireEvent(Events.BeforeChange, se) is also false, then the code this.value = value will never get executed, nor will the fireEvent ever get called. So therefore the value will never be set.

Thats actually what should happen.

Kennard Consulting
18 Aug 2009, 2:40 PM
sven,

Thank you for trying to help me.

Unfortunately I do not understand your response. Can you please explain why neither of the testcases I put in my original posting work?

How should I modify them so that I can...

1) set a value; and then
2) get that same value back from a Slider?

Regards,

Richard.

sven
18 Aug 2009, 2:43 PM
Default increment is 10. So 2 is a non valid value. You should try to debug your own code.

setValue(10) will work. Than getValue() also returns 10

Kennard Consulting
18 Aug 2009, 3:25 PM
Thank you for your help. I apologise for annoying you.