Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Combobox inside editable Table change selection when click to Column Sort
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;
}
}
Regards
Thanks for responding
This is the code
@SuppressWarnings("rawtypes")
private List getSorteos(){
List<ClMSorteoBean> clMSorteoBean = new ArrayList<ClMSorteoBean>();
StringBuffer sb = new StringBuffer();
sb.append("Select a ");
sb.append("From ClMSorteo a ");
List listobjects = mainComponent.getJpaPersistenceManagerService().getObjects(sb.toString());
for(int i=0;i<listobjects.size();i++){
ClMSorteo u = (ClMSorteo) listobjects.get(i);
String d = u.getClMProducto().getVdescripcion()+" "+u.getVtipo()+' '+u.getInumero()+' '+u.getDfecha();
clMSorteoBean.add(new ClMSorteoBean(u.getIidsorteo() ,d , u));
}
return clMSorteoBean;
}
public class ClMSorteoBean {
private int iidsorteo;
private String descripcion;
private ClMSorteo clMSorteo;
public ClMSorteoBean(int iidsorteo, String description,ClMSorteo clMSorteo) {
this.iidsorteo = iidsorteo;
this.descripcion = description;
this.clMSorteo = clMSorteo;
}
public int getIidsorteo() {
return iidsorteo;
}
public void setIidsorteo(int iidsorteo) {
this.iidsorteo = iidsorteo;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public ClMSorteo getClMSorteo() {
return clMSorteo;
}
public void setClMSorteo(ClMSorteo clMSorteo) {
this.clMSorteo = clMSorteo;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((clMSorteo == null) ? 0 : clMSorteo.hashCode());
result = prime * result
+ ((descripcion == null) ? 0 : descripcion.hashCode());
result = prime * result + iidsorteo;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClMSorteoBean other = (ClMSorteoBean) obj;
if (clMSorteo == null) {
if (other.clMSorteo != null)
return false;
} else if (!clMSorteo.equals(other.clMSorteo))
return false;
if (descripcion == null) {
if (other.descripcion != null)
return false;
} else if (!descripcion.equals(other.descripcion))
return false;
if (iidsorteo != other.iidsorteo)
return false;
return true;
}
}
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
}