0

problem with setSelected event on listbox.

asked 2009-11-08 12:47:19 +0800

sanhaq gravatar image sanhaq
264 1 6

Hi All,
I'm using a listbox as dropdown

<listbox id="l1" mold="select" rows="1" model="@{model.list}" selectedItem="@{model.selectedObj}">
.....
</listbox>

And I have one method in my composer onSelect$l1(Event anEvent){}.
Now whenever I'm a setting an object in my model calling the method setSelectedObj(obj) of my model it's automatically
calling the method onSelect$l1(Event anEvent) which I don't want.Plzz help.
I know that if I select a value from the dropdown at that time that onSelect$l1(Event anEvent) method should get fired.
But it's happing when I'm setting the value in model. How can I stop the calling of the onSelect$l1(Event anEvent) while I set the value in model.
Thanks,

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-11-08 19:25:58 +0800

joylo0122 gravatar image joylo0122
688 1
www.zkoss.org

@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

link publish delete flag offensive edit

answered 2009-11-09 09:02:59 +0800

mixgho gravatar image mixgho
193 3

Listboxes and especially Comboboxes are not good with selecting selectedItem. I recommend using selectedIndex instead by iterating through you collection model.

link publish delete flag offensive edit

answered 2009-11-09 11:21:25 +0800

sanhaq gravatar image sanhaq
264 1 6

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.

link publish delete flag offensive edit

answered 2009-11-09 14:12:44 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-09 14:32:59 +0800

| 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]

link publish delete flag offensive edit

answered 2011-03-01 23:42:28 +0800

yaryan997 gravatar image yaryan997
210 2

@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

link publish delete flag offensive edit

answered 2011-03-02 03:30:07 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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.

link publish delete flag offensive edit

answered 2011-03-02 05:51:25 +0800

yaryan997 gravatar image yaryan997
210 2

@ 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

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-11-08 12:47:19 +0800

Seen: 1,592 times

Last updated: Mar 02 '11

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