PDA

View Full Version : [FIXED] Different Listener behaviour TextField vs Radio



marswe
26 Aug 2008, 2:33 AM
Hi!

In the code below there is a difference between how Radios and TextField call events. The Radio always sends a change-event when the page is rendered, but not a TextField. Hence, I have to add the listener at the end of the code regarding the Radio but not the TextField. Why is there difference in the behaviour? This occured when changed from 1.02 to 1.1 alpha1.

/Markus


package com.mygwtest.client;

import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.widget.form.TextField;

public class Test implements EntryPoint {

public void onModuleLoad() {
ContentPanel panel = new ContentPanel();
panel.setSize(200, 200);
LayoutContainer container = new LayoutContainer();

FormLayout layout = new FormLayout(LabelAlign.TOP);
layout.setDefaultWidth(200);
container.setLayout(layout);

RadioGroup sellingUnit = new RadioGroup();
sellingUnit.setFieldLabel("Selling Unit");
Radio xWeight = new Radio();
xWeight.setBoxLabel("XWeight");
xWeight.setValue(true);
Radio sWeight = new Radio();
sWeight.setBoxLabel("SWeight");
sellingUnit.add(xWeight);
sellingUnit.add(sWeight);
container.add(sellingUnit);

TextField<String> test = new TextField<String>();
test.setFieldLabel("Test");
test.addListener(Events.Change, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent fe) {
System.out.println(fe.field);
}
});
test.setValue("Testing, testing");
panel.add(test);

panel.add(container);

RootPanel.get().add(panel);

xWeight.addListener(Events.Change, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent fe) {
System.out.println(fe.field);
}
});
}
}

darrellmeyer
27 Aug 2008, 12:41 PM
Fix is in SVN.

marswe
28 Aug 2008, 11:10 PM
Hmm, there are still some differences in the behaviour.

The listener on the radio button reacts in the example below, but not the listener for the textfield. This is the case even when I'm setting the value on the TextField after I added a listener but on the radio button the value is set and then listener is added, but still the radio fires a change event when page is loaded.


package com.mygwtest.client;

import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.widget.form.TextField;

public class TestApp implements EntryPoint {

public void onModuleLoad() {
ContentPanel panel = new ContentPanel();
panel.setSize(200, 200);
LayoutContainer container = new LayoutContainer();

FormLayout layout = new FormLayout(LabelAlign.TOP);
layout.setDefaultWidth(200);
container.setLayout(layout);

RadioGroup sellingUnit = new RadioGroup();
sellingUnit.setFieldLabel("Selling Unit");
Radio xWeight = new Radio();
xWeight.setBoxLabel("XWeight");
xWeight.setValue(true);
Radio sWeight = new Radio();
sWeight.setBoxLabel("SWeight");
sellingUnit.add(xWeight);
sellingUnit.add(sWeight);
xWeight.addListener(Events.Change, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent fe) {
System.out.println(fe.field);
}
});
container.add(sellingUnit);

TextField<String> test = new TextField<String>();
test.setFieldLabel("Test");
test.addListener(Events.Change, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent fe) {
System.out.println(fe.field);
}
});
test.setValue("Testing, testing");
panel.add(test);

panel.add(container);

RootPanel.get().add(panel);

}
}

/Markus

darrellmeyer
29 Aug 2008, 7:18 AM
The fix made it into the 1.0 release but not 1.1. The fix for 1.1 is in SVN.