Greetings Vaadin Community
Please someone could help me with this.
I have a table. It’s in editable mode. One column is represented by Comboboxes.
When I click in the header to sort or insert a new row in the table. The data selected in the combo in the previous rows disappear.
Thanks for your help
Jorge
table_2.setSelectable(true);
table_2.setEditable(true);
table_2.setImmediate(false);
table_2.setFooterVisible(true);
table_2.setColumnFooter("priceUSD", "Сумма");
table_2.setTableFieldFactory(goodsTableFactory);
table_2.setContainerDataSource(getTrlListContainer(""));
table_2.setVisibleColumns(new String[] {"clMSorteo", "mcolecciones", "menteros", "mboletos"});
table_2.setColumnHeaders(new String[] { "Sorteo", "Colecciones", "Enteros", "Boletos" });
table_2.setColumnExpandRatio("clMSorteo",2);
table_2.setColumnExpandRatio("mcolecciones",1);
table_2.setColumnExpandRatio("menteros",1);
table_2.setColumnExpandRatio("mboletos",1);
table_2.setColumnAlignment("mcolecciones",Table.ALIGN_RIGHT);
table_2.setColumnAlignment("menteros",Table.ALIGN_RIGHT);
table_2.setColumnAlignment("mboletos",Table.ALIGN_RIGHT);
private class GoodsTableFactory extends DefaultFieldFactory {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext)
{
Field field;
if ("clMSorteo".equals(propertyId)) {
final ComboBox combo = new ComboBox();
final BeanItemContainer goodsContainer = new BeanItemContainer(ClMSorteoBean.class, getSorteos());
combo.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
combo.setContainerDataSource(goodsContainer);
combo.setItemCaptionPropertyId("descripcion");
combo.setMultiSelect(false);
combo.setRequired(true);
combo.setInputPrompt("Por favor Seleccione un Producto");
combo.setWidth("100%");
field = combo;
} else {
field = super.createField(container, itemId, propertyId, uiContext);
}
return field;
}
}
After reading several forums can resolve the problem, let part of the code here in case anyone has the same problem
This code resolve
Combobox select/setValue and
Data selected in the combo in the previous rows disappear where click in the header to sort or insert a new row in the table.
Good Luck
@SuppressWarnings("unused")
private class GoodsTableFactory extends DefaultFieldFactory {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext)
{
Field field;
if ("clMSorteo".equals(propertyId)) {
final ComboBox combo = new ComboBox();
final BeanItemContainer<ClMSorteo> goodsContainer = new BeanItemContainer<ClMSorteo>(ClMSorteo.class);
goodsContainer.addAll(getSorteos());
combo.setContainerDataSource(goodsContainer);
combo.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
combo.setItemCaptionPropertyId("vdescripcionsorteo");
combo.setWidth("100%");
ClTrTransaccionl u = (ClTrTransaccionl) itemId;
combo.setValue(u.getClMSorteo());
field = combo;
} else {
field = super.createField(container, itemId, propertyId, uiContext);
}
return field;
}
}
public static IndexedContainer getTrlListContainer(String criterio) {
IndexedContainer container = new IndexedContainer();
container.addContainerProperty("clMSorteo", ClMSorteo.class,null);
container.addContainerProperty("mcolecciones", BigDecimal.class,null);
container.addContainerProperty("menteros", BigDecimal.class,null);
container.addContainerProperty("mboletos", Integer.class,null);
StringBuffer sb = new StringBuffer();
sb.append("Select a ");
sb.append("From ClTrTransaccionl a ");
// sb.append("Where a.clTrTransaccion.iidtransaccion = 0 ");
List listobjects = mainComponent.getJpaPersistenceManagerService().getObjects(sb.toString());
ClTrTransaccionl trl = new ClTrTransaccionl();
ClMSorteo so = new ClMSorteo();
trl.setClMSorteo(so);
trl.setMcolecciones(new BigDecimal(0));
trl.setMenteros(new BigDecimal(0));
trl.setMboletos(new Integer(0));
for(int i=0;i<listobjects.size();i++){
ClTrTransaccionl u = (ClTrTransaccionl) listobjects.get(i);
//Item item = container.addItem(listobjects.get(i));
Item item = container.addItem(u);
item.getItemProperty("clMSorteo").setValue(u.getClMSorteo());
item.getItemProperty("mcolecciones").setValue(u.getMcolecciones());
item.getItemProperty("menteros").setValue(u.getMenteros());
item.getItemProperty("mboletos").setValue(u.getMboletos());
}
return container;
}
@SuppressWarnings("rawtypes")
private List getSorteos(){
List<ClMSorteo> clMSorteoBean = new ArrayList<ClMSorteo>();
StringBuffer sb = new StringBuffer();
sb.append("Select a ");
sb.append("From ClMSorteo a ");
List listobjects = mainComponent.getJpaPersistenceManagerService().getObjects(sb.toString());
return listobjects;
}
@Entity @Table(name=“cl_m_sorteo”)
public class ClMSorteo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int iidsorteo;
@Temporal( TemporalType.DATE)
private Date dfecha;
private short inumero;
private BigDecimal mprecio;
private String vobservaciones;
private String vstts;
private String vtipo;
private String vdescripcionsorteo ;
… getter and setter, generated equals and hashCode methods
}