Помогите разобраться с Listener-ами.
Имеется простейший портлет на Vaadin.
Имеется на этом портлете пара button , table и nativeselect.
Кнопки работают нормально, таблица тоже. А вот после добавления nativeselect столкнулся с тем, что listener на select срабатывает только после listener на table.
Вот код:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
package samplePortlet;
import com.vaadin.Application;
import com.vaadin.ui.*;
import com.vaadin.*;
import com.vaadin.data.*;
import com.vaadin.ui.CustomComponent;
import com.vaadin.annotations.*;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.*;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.*;
import java.io.Serializable;
import com.vaadin.data.util.*;
@SuppressWarnings("serial")
public class samplePortlet extends Application {
@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private Panel panel_1;
@AutoGenerated
private VerticalLayout verticalLayout_1;
@AutoGenerated
private TabSheet tabSheet_1;
@AutoGenerated
private RichTextArea richTextArea_1;
@AutoGenerated
private Table table_1;
@AutoGenerated
private MenuBar menuBar_1;
private static final String FNAME = "First Name";
private static final String LNAME = "Last Name";
private static final String COMPANY = "Company";
private static final String[] fieldNames = new String[] { FNAME, LNAME,
COMPANY, "Mobile Phone", "Work Phone", "Home Phone", "Work Email",
"Home Email", "Street", "City", "Zip", "State", "Country" };
//IndexedContainer contactContainer = createDummyDatasource();
public void init() {
Window window = new Window();
setMainWindow(window);
Label label = new Label("Hello!");
window.addComponent(label);
window.addComponent(new WindowOpener("My sub-window", window)); // класс в этом пакете, в частности рисует кнопку и новое окно
/* Create the table with a caption. */
final Table table = new Table("This is my Table");
/* Define the names and data types of columns.
* The "default value" parameter is meaningless here. */
table.setWidth("650px");
table.setHeight("300px");
table.addContainerProperty("First Name", String.class, null);
table.addContainerProperty("Last Name", String.class, null);
table.addContainerProperty("Year", Integer.class, null);
/* Add a few items in the table. */
table.addItem(new Object[] {"Nicolaus","Copernicus",new Integer(1473)}, new Integer(1));
table.addItem(new Object[] {"Tycho", "Brahe", new Integer(1546)}, new Integer(2));
table.addItem(new Object[] {"Giordano","Bruno", new Integer(1548)}, new Integer(3));
table.addItem(new Object[] {"Galileo", "Galilei", new Integer(1564)}, new Integer(4));
table.addItem(new Object[] {"Johannes","Kepler", new Integer(1571)}, new Integer(5));
table.addItem(new Object[] {"Isaac", "Newton", new Integer(1643)}, new Integer(6));
table.addItem(new Object[] {"Crup", "Vlas", new Integer(1889)}, new Integer(225));
table.addItem(new Object[] {"Hren s gory", "Kakoy-to tam", new Integer(1977)}, new Integer(1977));
// Allow selecting items from the table.
table.setSelectable(true);
// Send changes in selection immediately to server
table.setImmediate(true);
// Shows feedback from selection.
final Label current = new Label("Selected: -");
// Handle selection change.
table.addListener(new Property.ItemChangeListener() {
});
table.addListener(new Table.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
current.setValue("Selected: " + table.getValue());
}
});
window.addComponent(table);
window.addComponent(current);
window.addComponent(new samplePortletpart("Add new part of products", window)); // класс в этом пакете, в частности рисует кнопку и новое окно
final NativeSelect select = new NativeSelect("My Selection");
// Add some items
select.addItem(new mySelectClass("123"));
select.addItem(new mySelectClass("234"));
select.addItem(new mySelectClass("33"));
select.setNullSelectionAllowed(false);
final Label labSelect = new Label("Basic Select Label");
select.addListener(new NativeSelect.ValueChangeListener(){
public void valueChange(ValueChangeEvent event) {
labSelect.setValue("Selected nativeValue: " + event.getProperty().getValue().toString());
}
});
window.addComponent(labSelect);
window.addComponent(select);
}
public class mySelectClass {
public String id;
public String name;
/**
* @param id
* @param name
*/
public mySelectClass (String name) {
super();
//this.id = id;
this.name = name;
}
public mySelectClass (String id, String name) {
super();
this.id = id;
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
}
Как видно из кода, я отслеживаю изменение Value Table и NativeSelect записывая значение в label. Так вот. Изменение в NativeSelect отображается в labSelect только после того, как сработает Listener на table.
Как я понимаю, Listener-ы обрабатываются в порядке очерёдности и так как у меня на Table "более первый", то отображение изменений на NativeSelect отображается только после прохождения изменений Table.
Мне же надо, что бы Listener-ы срабатывали независимо. Примеры (3 штуки) из vaadin book 6.4 с button у меня с Table и Select не прокатывает.
Можете подсказать, как это обойти?