Kamrul
(Kamrul Hasan)
March 27, 2019, 3:44am
1
In my web application i want to add some features like…
1.Combobox will enabled when i select a pre-targeted value on another multiselect combobox(Combobox will disable first).
2.I have a enum class and set this data in two different combobox.If i select one data then it will no longer available for another combobox.
Any expert here or anyone who can give me some idea?
Pekka29
(Pekka Maanpää)
April 1, 2019, 7:36am
2
Hi!
Does something like this work for you:
enum MyEnum {
FOO, BAR, BAZ
};
public MainView() {
ComboBox<MyEnum> comboBox1 = new ComboBox<>();
comboBox1.setItems(MyEnum.values());
ComboBox<MyEnum> comboBox2 = new ComboBox<>();
comboBox2.setEnabled(false);
comboBox1.addValueChangeListener(e -> {
if (e.getValue() == null) {
comboBox2.setValue(null);
comboBox2.setEnabled(false);
} else {
comboBox2.setItems(Arrays.stream(MyEnum.values())
.filter(value -> value != e.getValue()));
comboBox2.setEnabled(true);
}
});
add(comboBox1, comboBox2);
}
Kamrul
(Kamrul Hasan)
April 2, 2019, 8:14pm
3
Pekka Maanpää:
Hi!
Does something like this work for you:
enum MyEnum {
FOO, BAR, BAZ
};
public MainView() {
ComboBox<MyEnum> comboBox1 = new ComboBox<>();
comboBox1.setItems(MyEnum.values());
ComboBox<MyEnum> comboBox2 = new ComboBox<>();
comboBox2.setEnabled(false);
comboBox1.addValueChangeListener(e -> {
if (e.getValue() == null) {
comboBox2.setValue(null);
comboBox2.setEnabled(false);
} else {
comboBox2.setItems(Arrays.stream(MyEnum.values())
.filter(value -> value != e.getValue()));
comboBox2.setEnabled(true);
}
});
add(comboBox1, comboBox2);
}
Thanks expert.
Can you tell me how can i do it for List?
Pekka29
(Pekka Maanpää)
April 3, 2019, 8:56am
4
Not much difference, just get a Stream
out of the list instead of the enum:
comboBox2.setItems(list.stream()
.filter(value -> value != e.getValue()));
Kamrul
(Kamrul Hasan)
April 8, 2019, 6:06am
5
This is happening. can you please help me out?
Pekka29
(Pekka Maanpää)
April 8, 2019, 8:00am
6
Disabled components should ignore any updates from the client-side. If everything works fine, you don’t have to worry about those message logs.