-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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}"
value="@{win.current.Farmacia}" onSelect="cmbFarmChange()"readonly="true">
<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
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
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
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}"
value="@{win.current.Farmacia}" onSelect="cmbFarmChange()"readonly="true">
<comboitem self="@{each=order}" label="@{order.descrizione}" value="@{order.farmacia}"/>
</combobox>
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...
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(){
String descrizione="<not found>";
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
It could be:
public String desFarmacia(){ Comboitem ci = cmbFarmacie().getSelectedItem(); return ci.getDescription(); }
Asked: 2009-08-28 08:54:24 +0800
Seen: 410 times
Last updated: Sep 01 '09