-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All,
I'm using a listbox as dropdown
<listbox id="l1" mold="select" rows="1" model="@{model.list}" selectedItem="@{model.selectedObj}"> ..... </listbox>
@sabhaq
Hi sanhaq, are you using GenericForwardComposer? If you don't, please use it.
In this case, you can modified your code like here:
In Zul
<listbox id="l1" mold="select" rows="1"> ..... </listbox>
In GenericForwardComposer
private Listbox l1; public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); l1.setModel(ListModel); l1.setSelectedItem(Listitem item); }
Regards
/Joy
mixgho, joylo0122
thanks 4 ur reply.
joylo0122 could you please post a sample code example.
By the way do I need to write itemrenderer for this?
As I have one arraylist that cotains different object and the label of the list item would be set by a particual field value of the object resides in the arraylist.
And yes joylo0122 you said to pass Listitem object in the setSelected method
as mentioned by you... l1.setSelectedItem(Listitem item);
But I have an object available which I want to set as selected item. So how can make a listietm object and attach my object to pass it to the setselected method.
Plz help.
| But I have an object available which I want to set as selected item. So how can make a listietm object and attach my object to pass it to the setselected method.
Hi sanhaq,
1. you allways need an itemRenderer when using a listbox.
2. Like mixgho said: The way is the goal: yourListbox.setSelectedIndex(theListBoxesModel.indexOf(ObjectInItToSelect))
3. A few lines for selecting the needed Object in the listBoxes model.
// fill the listbox with the data of branches ListBoxkunBranche.setModel(new ListModelList(getBranchService().getAllBranches())); // set the ItemRenderer for this Listbox ListBoxkunBranche.setItemRenderer(new CustomerBrancheListModelItemRenderer()); // get the ListModelList for this Listbox for work with it ListModelList lml = (ListModelList) ListBoxkunBranche.getModel(); // get and select the customers branch Branche branche = kunde.getBranche(); // select the ListItem in the Listbox by an integerPosition by getting // it's position in the corresponding ListModelList (lml) ListBoxkunBranche.setSelectedIndex(lml.indexOf(branche));
The ItemRenderer
public class CustomerBrancheListModelItemRenderer implements ListitemRenderer, Serializable { private static final long serialVersionUID = 1L; private transient final static Logger logger = Logger.getLogger(CustomerBrancheListModelItemRenderer.class); @Override public void render(Listitem item, Object data) throws Exception { Branche branche = (Branche) data; if (logger.isDebugEnabled()) { logger.debug("--> " + branche.getBraNr() + "|" + branche.getBraBezeichnung()); } Listcell lc = new Listcell(branche.getBraBezeichnung()); lc.setParent(item); item.setAttribute("data", data); // ComponentsCtrl.applyForward(img, "onClick=onImageClicked"); // ComponentsCtrl.applyForward(item, "onClick=onClicked"); // ComponentsCtrl.applyForward(item, "onDoubleClick=onDoubleClicked"); } }
best
Stephan
PS: The whole codes are in the sources of my sample app. See [Forum Category: Announcements]
@terry
but if we had a hasmap value while loading all records than it gives Cannot convert Hashmap to Theclass named used..
java.util.HashMap cannot be cast to com.certilogo.ecc.backend.entities.CertilogoService at com.certilogo.ecc.frontend.ServiceListModelItemRenderer.render(ServiceListModelItemRenderer.java:22)
my ServiceListModelItemRenderer.java class is
public class ServiceListModelItemRenderer implements ListitemRenderer,Serializable { /** * */ private static final long serialVersionUID = 1L; private static final Logger logger = Logger.getLogger(ServiceListModelItemRenderer.class); public void render(Listitem item, Object data) throws Exception { // TODO Auto-generated method stub final CertilogoService service_list = (CertilogoService) data; final Listcell lc = new Listcell(service_list.getServiceName()); lc.setParent(item); item.setAttribute("data", data); //item.appendChild(lc); } }
I am calling this method from my basecontroller with onCreate event
public void onCreate$filter_bar() throws Exception { logger.info("ON CREATE EXECUTE"); System.out.println("Create"); System.out.println("Service Id initial " +getCkServiceIds()); //ListModelList //lbox_season.setModel(new ListModelList(getCertilogoServiceDao().getAllSeason(this.getCkServiceIds()))); lbox_service.setModel(new ListModelList(getCertilogoServiceDao().getAllServices(this.getCkServiceIds()))); lbox_service.setItemRenderer(new ServiceListModelItemRenderer()); ListModelList lml_service = (ListModelList) lbox_service.getModel(); //ListModelList lml_season = (ListModelList) lbox_season.getModel(); logger.info("Done"); }
help me to solve my problem...
Best Regards
YOgendra
Here are a few lines from an other method. Hope it can helps you to CAST your object out of the Map ( .getValue() )
Map<?, ?> m = (Map<?, ?>) data; if (m != null && !m.isEmpty()) { for (Map.Entry<?, ?> entry : m.entrySet()) { entry.getKey() entry.getValue()
Show us your getCertilogoServiceDao().getAllServices() method.
@ Terrytornado
Actually I had posted all my problems to you at the below link last query.
http://www.zkoss.org/forum/listComment/8221
which also contains getCertilogoServiceDao().getAllServices() method also.
Best Regard
YOgendra
Asked: 2009-11-08 12:47:19 +0800
Seen: 1,599 times
Last updated: Mar 02 '11