-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guys!
I have a model, pseudocode
public ListModel<City> getCityModel() {
return cityModel;
}
I need an ability to add "not selected" label to view which will have a null value. On zul page I have something like this
<combobox readonly="true" model="@load(vm.cityModel)" selectedItem="@bind(fx.city)">
<template name="model" var="c">
<comboitem value="@load(c.id)" label="@load(c.name)"/>
</template>
</combobox>
I used the same approach like here forum.zkoss.org/question/97747/how-to-add-an-empty-value-to-a-combobox/ (sorry, can't post a link) but I need not an empty label, but "not selected" or smth. I added my own comboitem with this code:
@Override
public void setLabel(String label) {
if (label == null) {
ComboboxWithEmptyValue cbx = (ComboboxWithEmptyValue) getParent();
if (cbx.getAddEmpty())
label = "not selected";
}
super.setLabel(label);
}
The problem that I get not selected label at the bottom of dropdown menu, and I need this on top. I tried to add null value to model to the first and to last position, but that changed nothing. Any ideas?
Thanks in advance for help!
Maybe there is something wrong with your code, try this :
@Override
public void setLabel(String label) {
if (label == null) {
label = "not selected";
}
super.setLabel(label);
}
@Override public void setLabel(String label) { if (label == null) { label = "not selected"; } super.setLabel(label); }
Tried the same code, doesn't work as I need
Asked: 2018-04-13 23:20:55 +0800
Seen: 30 times
Last updated: Apr 16 '18
Sort your listmodel so that empty value is first
chillworld ( 2018-04-15 12:39:54 +0800 )editHi chillworld! Thanks for your reply, but as I already wrote I tried sorting and nothing changes if null item is at first or at last position in ListModelList - the label not selected always at the bottom. If I don't use the label and leave just an empty combiotem, then it works.
pavelEW ( 2018-04-16 18:23:00 +0800 )edit