# Combobox problems...

lramellavotta
200 1 8

Hello everyone, I have the following problem:
I have a form divided into 2 tab. The first contains a list of records, the second the details of the selected record.

In detail I have a number of fields. I thought to associate with a field a combobox in order to simplify the data-entry. But when I enter the details can not get a description of the code.
Here's the code:

<!-- only display for debug ... -->
<textbox width="90%" value="@{win.current.Farmacia}" maxlength="15" />

<combobox id="cmbFarmacie" model="@{lstFa}" selectedItem="@{selected}"
<comboitem self="@{each=order}" label="@{order.descrizione}" value="@{order.farmacia}"/>
</combobox>

...

<![CDATA[
// leggo i records
List lstFa=win.showlistfarmacie();

void cmbFarmChange(){
win.setFarmacia(cmbFarmacie.getSelectedItem().getValue().toString());
//Messagebox.show("Farmacia selezionata:"+cmbFarmacie.getSelectedItem().getValue().toString());
}

...

lstFa contains records with the following fields (farmacia (key), descrizione (description of key))
win.current is a class of Customers(User,Description,Passwd,etc...)

Surely it is my mistake. I tried but I can not find the solution ... in theory should be so simple ... :(

Luca

delete retag edit

## 6 Replies

lramellavotta
200 1 8

Probably my English is terrible ...
The best example for what I want is a ComboBox to "Microsoft Access" ...
From the many examples I could not understand how to do ...
The important thing is that the combo includes a description and a key. When I select the record should set the field on the screen with the key ...
Thanks

YamilBracho
1722 2

A combobox is a collection of ComboItems.
A comboItem have :
- a label - What you see in the list and in the text part of the combo box
- a value - The value of the comboitem. Could be a full java object
- a description - a line of text that you can see when you display the list part of the combo, just below the "label"

HTH

lramellavotta
200 1 8

Thank's YamilBracho,
the problem in my code is that the ComboBox does not work as expected. Opening makes me actually see the description but once selected the correct record did not return a key .... Have I done something wrong?

Luca

<combobox id="cmbFarmacie" model="@{lstFa}" selectedItem="@{selected}"
<comboitem self="@{each=order}" label="@{order.descrizione}" value="@{order.farmacia}"/>
</combobox>

YamilBracho
1722 2

According your code, when you select an item you get "order.farmacia" as value...
When you execute the onSelect event in your combo yo state:
win.setFarmacia(cmbFarmacie.getSelectedItem().getValue().toString());
So you will the description in the textbox of your combobox
to be short you are put "order.farmacia" which is a string to your combo...

lramellavotta
200 1 8

Thank's YamilBracho,
your answer helped me. Now my code is as follows and it works.
I send the full code for beginner (like me!!!)

Farmacia/Attivo
<hbox>
<textbox id="txtFarmacia" width="30%" value="@{win.current.Farmacia}" maxlength="15" readonly="true"/>
<combobox id="cmbFarmacie" model="@{lstFa}" selectedItem="@{selected}" autodrop="true"
value="@{win.current.Farmacia}"
onSelect="cmbFarmacie.value=self.selectedItem.label;cmbFarmChange(cmbFarmacie.getSelectedItem(),self)">
<comboitem self="@{each=farm}" label="@{farm.descrizione}" value="@{farm.farmacia}"/>
</combobox>
...
...

<zscript>
<![CDATA[

...
...

void cmbFarmChange(Comboitem cmi, Combobox cmb)
{
if(scheda.isSelected()){

txtFarmacia.setValue(cmi.getValue().toString());
win.setFarmacia(cmi.getValue().toString());
}
}

void cmbSetDescrizione()
{
cmbFarmacie.setValue(win.desFarmacia());
}

======== end of .zul =====

(file .java)

public void setFarmacia(String txtFarmacia){
current.setFarmacia(txtFarmacia);
}

@SuppressWarnings("unchecked")
public String desFarmacia(){
Iterator it;
cmbFarmacie lstFarm;
for (it = lstcmbFarm.iterator(); it.hasNext(); ) {
lstFarm = (cmbFarmacie)it.next();
if(lstFarm.getFarmacia().equals(current.getFarmacia()))
{
descrizione=lstFarm.getDescrizione();
break;
}
}
return descrizione;
}

1) current = current record selected (class)
2) cmbFarmacie = class containing record order by descr (Key, Descr)

I have 2 tab in zul form:
1) list of rows records (tab-name ="elenco")
2) detail of selected record (tab-name="scheda")

When I select the detail I call the function desFarmacia() to find the correct description of the field (cmbFarmacie)...
I hope that my explanations are understandable..
Regards

YamilBracho
1722 2

It could be:

public String desFarmacia(){
Comboitem ci = cmbFarmacie().getSelectedItem();
return ci.getDescription();
}


[hide preview]