Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2013 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbai123/7332482 to your computer and use it in GitHub Desktop.
Save benbai123/7332482 to your computer and use it in GitHub Desktop.
ZK Chosenbox support item clicked event
package test;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkmax.zul.Chosenbox;
public class CustomChosenbox extends Chosenbox {
private static final long serialVersionUID = -5929845559826449285L;
static {
addClientEvent(CustomChosenbox.class, "onItemClicked", CE_IMPORTANT | CE_DUPLICATE_IGNORE | CE_NON_DEFERRABLE);
public CustomChosenbox () {
setWidgetOverride("doClick_", "function (evt) {\n"
+" this.$doClick_(evt);\n"
+" var $target = jq(evt.domTarget);\n"
+" if ($target.hasClass('z-chosenbox-sel-item-cnt'))\n"
+"'onItemClicked', {clickedItem: $target[0].innerHTML}, {toServer: true});\n"
public void service( request, boolean everError) {
final String cmd = request.getCommand();
// process custom event
if (cmd.equals("onItemClicked")) {
Events.postEvent("onItemClicked", this, request.getData());
} else {
super.service(request, everError);
<window id="win" apply="test.TestComposerTwo">
<chosenbox id="cbx" use="test.CustomChosenbox"
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
public class TestComposerTwo extends SelectorComposer {
private static final long serialVersionUID = -5358059094135126494L;
private ListModelList _model;
public ListModel getModel () {
if (_model == null) {
List l = new ArrayList();
l.add("item 1");
l.add("item 2");
l.add("item 3");
_model = new ListModelList(l);
return _model;
@Listen(" onItemClicked = #cbx")
public void doSomething (Event event) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment