0

Select a Listbox item in Java - using listmodel

asked 2009-01-13 02:18:38 +0800

erickmelo gravatar image erickmelo
87 2

Hi... Sorry for many questions, but I've one more:

In ZUL I have this code:

<listbox id="list" model="@{model.values}" selectedItem="@{model.selectedValue}" 

So, when an user select a Item from the list, the selectedValue is bind to the model.... It's OK

But I need do the same in Java... How databinding works in Java? I would like to have my bean set with the selected item model value... I also would like to select the item in Java... I have an "item" from "model.values", and would like to do this as the first selected item
My Java Code:

final Listbox valuebox = new Listbox();
valuebox.setModel(valueModelList);
valuebox.setItemRenderer(valueListItemRenderer);
valuebox.setMold("select");
valuebox.setRows(1);
valuebox.setMultiple(false);
// Select an item - valuebox.select(mybean.getValue() ) HOW????
valuebox.addEventListener("onSelect", new EventListener(){
	public void onEvent(Event arg0) throws Exception {
		Listitem item = valuebox.getSelectedItem();
		mybean.setValue( (Value) item.getValue());
}

Is this the way? Have I to implement a EventListener, to set the property in my bean? In my renderer I set Lisitem value with the "value" object...

The listbox has the selectItem(Listitem item) method... I don't have the Listitem object, but I've a Value object, that is in the model... So, how can I select this item, when I have a model and the the model contains the object I wish select ? In ZUL I have selectedItem="@{model.selectedValue}", but in Java?

I read some posts about this situation, but it's clear for me....

Thanks!

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-01-15 12:19:37 +0800

erickmelo gravatar image erickmelo
87 2

I didn't get a solution for this problem.... Can you help me?

link publish delete flag offensive edit

answered 2009-01-15 12:58:09 +0800

guleri gravatar image guleri
75 2

updated 2009-01-15 12:59:59 +0800

I think you can use

valuebox.setSelectedIndex(INT_INDEX_FOR_ITEM or a ListItem object);

Or you can set the attribute on one of the children ListItems;
listitem.setSelected(true);

Iterate over valuebox.getItems() and look for the id (not index) and set the selected item etc.
Dunno maybe there is a much more easy way also..?

link publish delete flag offensive edit

answered 2009-01-15 16:16:02 +0800

erickmelo gravatar image erickmelo
87 2

OK..

I think should have a method like:
valuebox.setSelectedItemFromModel(Object object);

So, Zk should search in the ListModel for the object and set the right ListItem as selected;

<listbox id="list" model="@{model.values}" selectedItem="@{model.selectedValue}" 

In ZUL it is done... I've a model, and the selectedItem is binded to a bean.. So, when I change the model.selectedValue ZK set the right selected Listitem...

In Java I have to:
- Iterate over valuebox.getItems()
- Compare Listitem value with my bean
- Set Listitem.selected property

I think doing this work in ZUL is better, but in some cases it's not possible (Tabbox generated on-the-fly). So I have to do it in Java... I thunk ZK should provide the same king of options in ZUL also in Java... (annotation dataBinder, item selection: model="@{model.values}" selectedItem="@{model.selectedValue}"). If is possible do it in Java too easy as in ZUL, please help me, because I've found some problems with it.

[]s

link publish delete flag offensive edit

answered 2009-01-15 16:34:14 +0800

guleri gravatar image guleri
75 2

Well the whole system is written i java, so i guess it should be possible to use the same classes/interfaces as the zul files. Have not digned deep enougth into the source code there yet. I think there is some small talkes about the things behind the sceen there also..

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
1 follower

RSS

Stats

Asked: 2009-01-13 02:18:38 +0800

Seen: 1,119 times

Last updated: Jan 15 '09

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