示例#1
0
        public void render(Listitem item, final Object data) {
          final Listbox listbox = (Listbox) item.getParent();
          final Template tm = listbox.getTemplate("model");
          if (tm == null) {
            item.setLabel(Objects.toString(data));
            item.setValue(data);
          } else {
            final Component[] items =
                tm.create(
                    listbox,
                    item,
                    new VariableResolver() {
                      public Object resolveVariable(String name) {
                        return "each".equals(name) ? data : null;
                      }
                    });
            if (items.length != 1)
              throw new UiException(
                  "The model template must have exactly one item, not " + items.length);

            final Listitem nli = (Listitem) items[0];
            if (nli.getValue() == null) // template might set it
            nli.setValue(data);
            item.setAttribute("org.zkoss.zul.model.renderAs", nli);
            // indicate a new item is created to replace the existent one
            item.detach();
          }
        }