/** * @since 3.0.2 */ public Object coerceToBean(Object val, Component comp) { final Combobox cbbox = (Combobox) comp; if (Executions.getCurrent().getAttribute("zkoss.zkplus.databind.ON_SELECT" + cbbox.getUuid()) != null) { //bug #2140491 //triggered by coerceToUi(), ignore this Executions.getCurrent().removeAttribute("zkoss.zkplus.databind.ON_SELECT" + cbbox.getUuid()); return TypeConverter.IGNORE; } if (val != null) { final ListModel model = cbbox.getModel(); //Bug #2010389 //1. loadAll //2. setModel (by 1.), post onInitRender. //3. setSelectedItem (by 1.), coerceToUi, post onSelect with OLD Comboitem. //4. onInitRender(by 2.), syncModel and reconstruct new Comboitem(s) list, fire onInitRenderLater //** 5. save (by 3.), coreceToBean with OLD Comboitem, cannot locate the index with indexOf() //6. onInitRenderLater(by 4.), setSelectedItem, coerceToUi, post onSelect with new Comboitem //no model case, assume Comboitem.value to be used with selectedItem return model != null ? model.getElementAt(cbbox.getItems().indexOf(val)) : ((Comboitem) val).getValue(); } return null; }
items.add(item); Executions.getCurrent().setAttribute("zkoss.zkplus.databind.ON_SELECT" + cbbox.getUuid(), Boolean.TRUE); Events.postEvent(new SelectEvent<Comboitem, Object>("onSelect", cbbox, items, item));
public void render(Component comp, Writer out) throws IOException { final SmartWriter wh = new SmartWriter(out); final Combobox self = (Combobox) comp; final String uuid = self.getUuid(); final String zcls = self.getZclass(); final Execution exec = Executions.getCurrent(); wh.write("<span id=\"").write(uuid).write("\"") .write(self.getOuterAttrs()) .write(" z.type=\"zul.cb.Cmbox\" z.combo=\"true\"><input id=\"") .write(uuid).write("!real\" autocomplete=\"off\"") .write(" class=\"").write(zcls).write("-inp\"") .write(self.getInnerAttrs()).write("/><span id=\"") .write(uuid).write("!btn\" class=\"").write(zcls).write("-btn\""); if (!self.isButtonVisible()) wh.write(" style=\"display:none\""); wh.write("><img class=\"").write(zcls).write("-img\" onmousedown=\"return false;\""); wh.write(" src=\"").write(exec.encodeURL("~./img/spacer.gif")).write("\"") .write("\"/></span><div id=\"").write(uuid).write("!pp\" class=\"") .write(zcls).write("-pp\" style=\"display:none\" tabindex=\"-1\">") .write("<table id=\"").write(uuid) .write("!cave\" cellpadding=\"0\" cellspacing=\"0\">") .writeChildren(self) .write("</table></div></span>"); } }