Set value in dynamic combobox

Hi.

I have a ComboBox with items add from query:


              (...)

	       final ArrayList<NombreConceptoSelectItem<Integer>> nombreConceptos = new ArrayList<NombreConceptoSelectItem<Integer>>();
	
              (...)

		if (modelLocator.conceptoList != null) {
			for (ConceptoVO concepto : modelLocator.conceptoList) {
		    	nombreConceptos.add(new NombreConceptoSelectItem<Integer>(concepto.getNombre(), concepto.getId()));
		    }
		}

NombreConceptoSelectItem:


public class NombreConceptoSelectItem<T> {
	
	String caption;
	T value;
	
	public NombreConceptoSelectItem(String caption, T value) {
		super();
		this.caption = caption;
		this.value = value;
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public T getValue() {
		return value;
	}

	public void setValue(T value) {
		this.value = value;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((caption == null) ? 0 : caption.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NombreConceptoSelectItem other = (NombreConceptoSelectItem) obj;
		if (caption == null) {
			if (other.caption != null)
				return false;
		} else if (!caption.equals(other.caption))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}
	
}

I have a table with a column of type ConceptoVO and a form with field for add/change its value.

The form implements com.vaadin.ui.FormFieldFactory:


		partidaForm.setFormFieldFactory(new FormFieldFactory() {

			(...)
		    
			@Override
			public Field createField(Item item, Object propertyId, Component uiContext) {
				AbstractTextField field;
				
		    	boolean enabled = true;
		    	
		        if ("numeroFactura".equals(propertyId)) {
		            (...)
		        } else if ("concepto".equals(propertyId)) {
		        	ComboBox nombreConcepto = new ComboBox("Concepto");
		        	nombreConcepto.addValidator(new NombreConceptoValidator());
		        	nombreConcepto.setEnabled(enabled);
		        	nombreConcepto.setNullSelectionAllowed(false);
		            Property.ValueChangeListener listener = new Property.ValueChangeListener() {
		        	    public void valueChange(ValueChangeEvent event) {
		        	    	saveButton.setEnabled(partidaForm.isModified());
		        	    	discardChanges.setEnabled(partidaForm.isModified());
		        	    }
		        	};
		        	nombreConcepto.addListener(listener);
		        	nombreConcepto.setImmediate(true);
		            for (NombreConceptoSelectItem<?> tc : nombreConceptos) {
		            	nombreConcepto.addItem(tc.getValue());
		            	nombreConcepto.setItemCaption(tc.getValue(), tc.getCaption());
		            }
		            nombreConcepto.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_EXPLICIT);
		            nombreConcepto.requestRepaint();
		            
		            return nombreConcepto;
		        } else {
		        	field = null;
		        }
		        
		        (...)

		        return field;
			}
				
		});

My table has a ValueChangeListaner:


	public void onChangePartidaSelected(ValueChangeEvent event) {
		// in multiselect mode, a Set of itemIds is returned,
        // in singleselect mode the itemId is returned directly
        Set<PartidaVO> value = (Set<PartidaVO>) event.getProperty().getValue();
        Iterator<PartidaVO> valueIt = value.iterator();
        PartidaVO partidaVO = new PartidaVO();
        if (valueIt.hasNext()) {
        	partidaVO = valueIt.next();
        }
        
        (...)
        
        addItemInForm(partidaVO);
	}

But when I select a item in table the value of comboBox not selected correctly.

I have other view with the same table and form but items in comboBox are “static” and work correctly:


			final ArrayList<TipoConceptoSelectItem<?>> tipoConceptos =
					new ArrayList<TipoConceptoSelectItem<?>>(
						    Arrays.asList(
						    		new TipoConceptoSelectItem<Integer>("Ingreso", 1),
						    		new TipoConceptoSelectItem<Integer>("Gasto", 2)));

Any ideas?

Thanks
12475.png

Nothing???