ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

Databinding problem

gdamato
30 Mar 2011 05:21:33 GMT
30 Mar 2011 05:21:33 GMT

hi, I have a problem with the databinding. When I use a listbox with a combobox with autocomplete: on selecting the first row of the listbox, combobox load only the corrisponding value. On selecting an other row, the combobox doesn't update the new value. I'm setting only value property a and I use a SimpleModelList, because BindindDataListModelList load all records without filtering values while the user starts to type... SOS please! :(

satshcool
12 May 2011 03:31:24 GMT
12 May 2011 03:31:24 GMT

if you haven't found a solution, post an example of your code here

gdamato
20 Jun 2011 11:37:51 GMT
20 Jun 2011 11:37:51 GMT

No, I haven't found a solution. In my page Controller I written:

public void onClick$btnSave(Event event) throws InterruptedException {
Transaction tx = null;
try {
Session session = HBConnection.getSession();
tx = session.beginTransaction();

if (isEditMode()) {
if (validate()) {
//save into bbe_rdv_servizi
binder.saveComponent(rdvVoloEdit); //reload model to force refresh

//store into db
if (_create) {
selected.setRdvNumpos(UtiBbeWeb.getNewNumPos(session, bbeRdvCurrent.getIdRdv()));
EntityManager.updateRecord(session, selected);
collRdvSrvVoli.add(selected);

if (chkRitorno.isChecked()) {
// Creazione automatica del bean di ritorno
BbeRdvServizi newBean = new BbeRdvServizi();
newBean.setBbeRdv(bbeRdvCurrent);
bbeRdvCurrent.getBbeRdvServizis().add(newBean);
newBean.setRdvNumpos(UtiBbeWeb.getNewNumPos(session, bbeRdvCurrent.getIdRdv()));
newBean.setRdvTiposervizio(Constants.BBE_TIPOSERVIZIO_AEREO);
newBean.setRdvStatoservizio(Constants.BBE_STATOSERVIZIO_INSERITO);
newBean.setRdvOrigine((String)rdvDestcitta.getSelectedItem().getValue());
newBean.setRdvDestcitta((String)rdvOrigine.getSelectedItem().getValue());
newBean.setRdvDatain(UtilStr.formatDataToDB(rdvDataritorno.getText()));
newBean.setRdvOrain(UtilStr.formatOraToDB(rdvOraritorno.getText()));
newBean.setRdvTipoposto(selected.getRdvTipoposto());
if (rdvTariffaRitorno.getSelectedItem()!=null) newBean.setRdvTariffa((String)rdvTariffaRitorno.getSelectedItem().getValue());
newBean.setRdvNote(selected.getRdvNote());
EntityManager.updateRecord(session, newBean);
collRdvSrvVoli.add(newBean);

clearCheckObject();
}
}
else {
EntityManager.updateRecord(session, selected);
}
//refresh the todoList
refreshModel();
//switch to view mode
setEditMode(false);
}
}

tx.commit();
}
catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
if (tx != null && tx.isActive()) {
try {
// Second try catch as the rollback could fail as well
tx.rollback();
}
catch (HibernateException e1) {
log.debug("Salvataggio volo: Errore rolling back transaction");
}
}
Messagebox.show(Labels.getLabel("app.msg.errGenerico"), Constants.APPL_NAME, Messagebox.OK, Messagebox.ERROR);
}
}

In the zul page I written this:

<listbox id="listboxVoli" multiple="false" selectedItem="@{controller.selected}" model="@{controller.allSrvVoli}">
<listhead sizable="true">
<listheader label="Data partenza" width="20%" id="colDatain" image="/img/v_hint.gif"/>
<listheader label="Ora partenza" width="20%" id="colOrain" image="/img/v_hint.gif"/>
<listheader label="Partenza da" width="25%" id="colOrigine" image="/img/v_hint.gif"/>
<listheader label="Destinazione" width="30%" id="colDestcitta" image="/img/v_hint.gif"/>
<listheader width="5%"/>
</listhead>
<listitem self="@{each=bbeRdvServizi}">
<listcell label="@{bbeRdvServizi.rdvDatain, converter='it.cisalpina.bbeweb.utils.ui.DateConverter'}" />
<listcell label="@{bbeRdvServizi.rdvOrain, converter='it.cisalpina.bbeweb.utils.ui.TimeConverter'}" />
<listcell label="@{bbeRdvServizi.rdvOrigine}" />
<listcell label="@{bbeRdvServizi.rdvDestcitta}" />
<listcell label="@{bbeRdvServizi.rdvStatoservizio, converter='it.cisalpina.bbeweb.utils.ui.ImageConverter'}" />
</listitem>
</listbox>
<div id="rdvVoloEdit" visible="@{controller.editMode}">
<separator spacing="50px"/>
<grid....
<rows>
<row spans="1,1,4" zclass="none">
<label value="* Partenza da:" sclass="labelBold" />
<combobox width="250px" id="rdvOrigine" value="@{controller.selected.rdvOrigine, save-when=none}" autodrop="true" buttonVisible="false" maxlength="50" constraint="strict,no empty" />
</row>
<row spans="1,1,4" zclass="none">
<label value="* Destinazione:" sclass="labelBold" />
<combobox width="250px" id="rdvDestcitta" value="@{controller.selected.rdvDestcitta, save-when=none}" autodrop="true" buttonVisible="false" maxlength="50" constraint="strict,no empty" />
</row>
.....

The first row selected in the listbox load correctly the autocomplete combobox. When you select the second row, the combobox shows the data of the previous row.
If I delete the first row, the second row shows the data correctly.

Thanks.
Grazia

duqinfang
20 Jun 2011 22:35:30 GMT
20 Jun 2011 22:35:30 GMT

hello

RyanWu
30 Jun 2011 19:39:55 GMT
30 Jun 2011 19:39:55 GMT

hi, i created a case and try to duplicate the problem,

Code
http://zkfiddle.org/sample/p5q2bc/4-Databinding-Test

Result
Online Preview

it's no problem with databinding and combobox

could you please preview more information about your project ?

dpino
30 Jun 2011 20:07:55 GMT
30 Jun 2011 20:07:55 GMT

What you're describing is the expected behaviour. The Combobox is actually a Textbox, you can type on it, that in addition it also has a List. When you select a value in the list, the Textbox is set with the text value of that elements. Once you deploy the list again, the Combobox only shows the values that matches the text already introduced, that's why you only see one value. If you clear that value, and type again from the beginning you can look up in all the values that are loaded in the list. This is how the autocomplete combobox works.

If you don't have a very long list, you can use a Listbox (type="select") (that also has search capabilities if I recall correctly) instead of a Combobox.

Hope this helps.

Diego

gdamato
1 Jul 2011 04:25:25 GMT
1 Jul 2011 04:25:25 GMT

Hi RyanWu,

I saw your demo. In my application degree object is a String and the combobox is loaded from another class.
In TestComposer on onCreate$win I write:
degree.setModel(new SimpleListModel(getList));

getList is a "private List<String> listDestinations". For load this list in doAfterCompose in TestComposer I write

setListDestinations(DestinationsManager.getDestinations(Costants.BBE_TIPOSERVIZIO_AEREO));

DestinationsManager.getDestinations(Costants.BBE_TIPOSERVIZIO_AEREO) charge the values from db.

In my zul file:
<combobox width="250px" id="degree" value="@{controller.selected.degree, save-when=none}" autodrop="true" buttonVisible="false" maxlength="50" constraint="strict,no empty"/>


Hi Diego,

I would like to use the Combobox. I want to use just the combox with autocomplete... if possible! :)

Many thanks to all :)

Hi Grazia

tulF
9 Jul 2011 03:46:02 GMT
9 Jul 2011 03:46:02 GMT

Have you found a solution? ;)

Silly

gdamato
11 Jul 2011 02:44:30 GMT
11 Jul 2011 02:44:30 GMT

No... I don't found a solution! :(

jimmyshiau
28 Jul 2011 10:41:01 GMT
28 Jul 2011 10:41:01 GMT

Hi gdamato
I think ryan's demo just update the model of combobox, when select a listitem,
so what effect do you want,
is it just update the value of combobox when select a listitem?