Created
November 6, 2013 07:59
-
-
Save benbai123/7332482 to your computer and use it in GitHub Desktop.
ZK Chosenbox support item clicked event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
+" this.fire('onItemClicked', {clickedItem: $target[0].innerHTML}, {toServer: true});\n" | |
+"\n}"); | |
} | |
public void service(org.zkoss.zk.au.AuRequest 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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<zk> | |
<window id="win" apply="test.TestComposerTwo"> | |
<chosenbox id="cbx" use="test.CustomChosenbox" | |
model="${win$composer.model}"/> | |
</window> | |
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Map; | |
import org.zkoss.zk.ui.event.Event; | |
import org.zkoss.zk.ui.select.SelectorComposer; | |
import org.zkoss.zk.ui.select.annotation.Listen; | |
import org.zkoss.zul.ListModel; | |
import org.zkoss.zul.ListModelList; | |
@SuppressWarnings("rawtypes") | |
public class TestComposerTwo extends SelectorComposer { | |
private static final long serialVersionUID = -5358059094135126494L; | |
private ListModelList _model; | |
@SuppressWarnings("unchecked") | |
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) { | |
System.out.println(((Map)event.getData()).get("clickedItem")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment