ZK getting selected item from combobox
I am trying to get selected value in combobox but it returns as a ComboItem.How can I get value as string?
<zscript>
<![CDATA[
String[] months = { "Ada", "Basic", "C", "C++", "Cobol", "Forth",
"Fortran", "Go", "Groovy", "Haskell", "Java", "JavaScript", "Lisp",
"Python", "Ruby", "Scala", "Scheme" };
ListModel lmonths = new SimpleListModel(months);
]]></zscript>
<combobox id="searchCombo"
f开发者_运维知识库orward="onChange=onSearch" model="@{months}" >
<!--
<comboitem self="@{each='months'}"
label="@{months}" value="@{months}">
</comboitem>
-->
</combobox>
And here my onSearch method
public void onSearch(ForwardEvent event) {
System.out.println(searchCombo.getSelectedItem());
prodevt.search(searchCombo.getSelectedItem().toString());
filterCbox.setChecked(true);
AnnotateDataBinder binder = (AnnotateDataBinder) win.getVariable(
"binder", true);
binder.loadAll();
}
I solved it like
searchCombo.getSelectedItem().getValue().toString();
ZK's databinding with combobox is very powerful,
i created a sample to sync select data from comboboxes and listbox
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
<zscript>
<![CDATA[
String[] langs = { "ZK" ,"Ada", "Basic", "C", "C++", "Cobol", "Forth",
"Fortran", "Go", "Groovy", "Haskell", "Java",
"JavaScript","Lisp", "Python", "Ruby", "Scala",
"Scheme"
};
//(Optional) Default Select ZK
String things_i_have_selected = langs[0];
]]></zscript>
<hlayout>
<combobox model="@{langs}" selectedItem="@{things_i_have_selected}" />
<combobox model="@{langs}" selectedItem="@{things_i_have_selected}" />
<listbox model="@{langs}" selectedItem="@{things_i_have_selected}"
rows="5" width="400px">
<listitem self="@{each=String}">
<listcell label="@{String}"></listcell>
</listitem>
</listbox>
</hlayout>
</zk>
what i want to say is that you don't need to get the selection item's value :)
Reference
- ZK Demo
- ZK Essentials#Implementing Data Binding
searchCombo.getSelectedItem().getValue() --> get value of selected ComboItem
searchCombo.getSelectedItem().getLabel() --> get text of selected ComboItem
精彩评论