0

Combobox problems...

asked 2009-08-28 08:54:24 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

updated 2009-08-28 08:57:44 +0800

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

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2009-08-30 19:30:27 +0800

lramellavotta gravatar image lramellavotta flag of Italy
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

link publish delete flag offensive edit

answered 2009-08-31 13:47:14 +0800

YamilBracho gravatar image 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

link publish delete flag offensive edit

answered 2009-09-01 07:31:52 +0800

lramellavotta gravatar image lramellavotta flag of Italy
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}"
value="@{win.current.Farmacia}" onSelect="cmbFarmChange()"readonly="true">
<comboitem self="@{each=order}" label="@{order.descrizione}" value="@{order.farmacia}"/>
</combobox>

link publish delete flag offensive edit

answered 2009-09-01 14:39:18 +0800

YamilBracho gravatar image 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...

link publish delete flag offensive edit

answered 2009-09-01 15:36:31 +0800

lramellavotta gravatar image lramellavotta flag of Italy
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(){
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

link publish delete flag offensive edit

answered 2009-09-01 16:13:00 +0800

YamilBracho gravatar image YamilBracho
1722 2

It could be:

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-08-28 08:54:24 +0800

Seen: 410 times

Last updated: Sep 01 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More