-
FEATURED COMPONENTS
First time here? Check out the FAQ!
How can I deselect a listbox by clicking on empty space on the page? How to get zk component under the cursor and how to set a handler?
hi brastilav! look at fiddle: link text select an item and click out i hope help you...
Hi mhj, thanx for the answer!
I'm still not sure how to do this, because onBlur event fires even when I change selection in the listbox. Try the following :
onBlur event should fire only when component looses focus right? In your example, onBlur fires even when I change selected items.
Basically, I want to do smth like this :
@Listen("onBlur=#clientsLb")
public void onBlurClientsLb(Event e) {
logger.debug("onBlur");
Listbox lb = (Listbox) e.getTarget();
lb.setSelectedItem(null);
}
This will not work properly, I don't know why.
Have a look on this code
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal" id="inp"
viewModel="@id('vm') @init('com.notify.MyListbox')" apply="org.zkoss.bind.BindComposer" >
<button label="AddItem" onClick="@command('addNewItem')" ></button>
<listbox model="@bind(vm.dataList)" selectedItem="@bind(vm.selectedItem)" onBlur="@command('onBlurMethod')">
<listhead>
<listheader value="A"></listheader>
<listheader value="B"></listheader>
<listheader value="C"></listheader>
</listhead>
<template name="model" var="mymodel">
<listitem>
<listcell >
<textbox value="@bind(mymodel.a)" onChange="@command('changeTextBox',data = mymodel)"/>
</listcell>
<listcell>
<textbox value="@bind(mymodel.b)" onChange="@command('changeAnotherTextBox',data = mymodel)"/>
</listcell>
<listcell>
<label value="@bind(mymodel.c)" />
</listcell>
</listitem>
</template>
</listbox>
</window>
</zk>
MVVM view Model
package com.notify;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Component;
// TODO: Sjoshi
/**
* The Class MyListbox.
*/
public class MyListbox {
/** The data list. */
private List<Data> dataList;
/** The selected item. */
private Data selectedItem;
/**
* After compose.
*
* @param view the view
*/
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
try {
dataList = new ArrayList<Data>();
Data data;
data = new Data("a1", "b1", "c1");
dataList.add(data);
data = new Data("a2", "b2", "c2");
dataList.add(data);
data = new Data("a3", "b3", "c3");
dataList.add(data);
} catch (Exception e) {
}
}
/**
* Change text box.
*
* @param data the data
*
* Taken from ZK Forum
*/
@Command
public void changeTextBox(@BindingParam("data") Data data) {
data.setB("Hariom=>" + data.getA());
BindUtils.postNotifyChange(null, null, data, "b");
}
@Command
@NotifyChange("selectedItem")
public void onBlurMethod(){
selectedItem = null;
}
/**
* Change another text box.
* Praposed By Nitin
*/
@Command
public void changeAnotherTextBox() {
selectedItem.setC("Hariom=>" + selectedItem.getB());
BindUtils.postNotifyChange(null, null, selectedItem, "c");
}
/**
* Adds the new item.
*/
@Command
@NotifyChange("dataList")
public void addNewItem() {
Data data = new Data("", "", "");
dataList.add(data);
}
/**
* Gets the data list.
*
* @return the data list
*/
public List<Data> getDataList() {
return dataList;
}
/**
* Sets the data list.
*
* @param dataList the new data list
*/
public void setDataList(List<Data> dataList) {
this.dataList = dataList;
}
/**
* The Class Data.
*/
public class Data {
/** The a. */
String a;
/** The b. */
String b;
/** The c. */
String c;
/**
* Gets the a.
*
* @return the a
*/
public String getA() {
return a;
}
/**
* Gets the b.
*
* @return the b
*/
public String getB() {
return b;
}
/**
* Gets the c.
*
* @return the c
*/
public String getC() {
return c;
}
/**
* Sets the a.
*
* @param a the new a
*/
public void setA(String a) {
this.a = a;
}
/**
* Sets the b.
*
* @param b the new b
*/
public void setB(String b) {
this.b = b;
}
/**
* Sets the c.
*
* @param c the new c
*/
public void setC(String c) {
this.c = c;
}
/**
* Instantiates a new data.
*
* @param a the a
* @param b the b
* @param c the c
*/
public Data(String a, String b, String c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
}
/**
* Gets the selected item.
*
* @return the selected item
*/
public Data getSelectedItem() {
return selectedItem;
}
/**
* Sets the selected item.
*
* @param selectedItem the new selected item
*/
public void setSelectedItem(Data selectedItem) {
this.selectedItem = selectedItem;
}
}
Asked: 2013-03-07 16:43:45 +0800
Seen: 62 times
Last updated: Oct 07 '14
Make conditional drop effect according to dragged widget ?
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
i have this problem too, please say the suggestion
fiendnet ( 2014-10-02 14:18:38 +0800 )edit