18 package org.turro.jpa.input;
20 import java.util.List;
21 import org.turro.i18n.I_;
22 import org.turro.jpa.Dao;
23 import org.turro.zkoss.input.GenericListbox;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zul.Listitem;
37 private boolean autoSave =
true;
38 private boolean allowNull;
39 private String nullLabel =
"None";
44 public JpaListbox(
Dao dao, String query,
boolean checkmark,
boolean autoSave) {
47 this.autoSave = autoSave;
48 setCheckmark(checkmark);
56 this.autoSave = autoSave;
77 if(dao ==
null)
return;
79 Listitem li =
new Listitem(
I_.
get(nullLabel),
null);
82 for(Object o : dao.getResultList(query)) {
89 addEventListener(Events.ON_SELECT,
new EventListener() {
91 public void onEvent(Event event)
throws Exception {
92 for(Listitem li : (List<Listitem>) getItems()) {
93 if(
getChecked((V) li.getValue()) != li.isSelected()) {
94 setChecked((V) li.getValue(), li.isSelected());
96 dao.saveObject(li.getValue());
113 this.allowNull = allowNull;
121 this.nullLabel = nullLabel;
125 protected boolean equals(V value, V obj) {
128 return (v1 ==
null && v2 ==
null) ||
129 (v1 !=
null && v1.equals(v2));
static String get(String msg)