@Override public FormItemRepresentation getRepresentation() { ComboBoxRepresentation rep = super.getRepresentation(new ComboBoxRepresentation()); List<OptionRepresentation> elements = new ArrayList<OptionRepresentation>(); for (String label : this.items.keySet()) { OptionRepresentation opt = new OptionRepresentation(); opt.setLabel(label); opt.setValue(this.items.get(label)); elements.add(opt); } rep.setElements(elements); rep.setName(this.name); rep.setId(this.id); return rep; }
@Override public void populate(FormItemRepresentation rep) throws FormBuilderException { if (!(rep instanceof ComboBoxRepresentation)) { throw new FormBuilderException( i18n.RepNotOfType(rep.getClass().getName(), "TextFieldRepresentation")); } super.populate(rep); ComboBoxRepresentation crep = (ComboBoxRepresentation) rep; List<OptionRepresentation> options = crep.getElements(); this.items.clear(); if (options != null) { for (OptionRepresentation option : options) { this.items.put(option.getLabel(), option.getValue()); this.listBox.addItem(option.getLabel(), option.getValue()); } } this.listBox.clear(); addItems(this.items, this.listBox); this.name = crep.getName(); this.id = crep.getId(); populate(this.listBox); }