I have a Grid with some editable columns. Most are effectively text fields, but one is a ComboBox and one is a DateField. When I hide two read only fields, something weird happens: the first time I click on the line to edit it, the ComboBox and DateField work fine. But then if I click on another line, they both are effictively read only/disabled. This is NOT at the Java level, this is in the HTML for the edit form. If I exit the edit form, and come back, it will work. I get around it for now with the following code, triggered when I click the line:
private void selectItemFromGrid( ItemClickEvent event ) {
if (gridComponent.isEditorEnabled())
{
Object itemId = event.getItemId();
if( itemId instanceof CalculatorPlan &&
((PlanType) itemId).getWmsItem() instanceof String &&
!((PlanTypeImpl) itemId).getWmsItem().trim().equals(emptyItem.getWmsItem().trim()))
{
Object selectedItem = gridComponent.getSelectedRow();
CalculatorPlan plan = (CalculatorPlan) itemId;
// Field<?> field = gridComponent.getColumnEditField("chosenDesignNumSignals");
// Field<?> field = gridComponent.getColumnEditField("chosenDesignNumBins");
Field<?> field = gridComponent.getColumnEditField("chosenDesignNumBinsOrResizedBins");
UI ui = getUI();
if(field instanceof ComboBox)
{
ComboBox chosenNumBins = (ComboBox) field;
if( gridComponent.isAnyColumnHidden() )
{
ui.access(()->{
chosenNumBins.setReadOnly(true);
ui.push();
chosenNumBins.setReadOnly(false);
ui.push();
});
}
String numBins = plan.getChosenDesignNumBins();
settingUpChosenDesignNumBinCombo = true;
chosenNumBins.removeAllItems();
if(!plan.isKeepOrderQty())
{
chosenNumBins.addItem("-9999");
chosenNumBins.setItemCaption("-9999", "HOLD");
}
if( plan.getSignal() instanceof List && !plan.getSignal().isEmpty())
{
List<SignalType> signals = plan.getSignal();
for( SignalType signal : signals)
{
chosenNumBins.addItem(signal.getNumBins());
}
chosenNumBins.setValue(numBins);
}
settingUpChosenDesignNumBinCombo = false;
if(plan.isKeepOrderQty())
{
chosenNumBins.setReadOnly(true);
}
}
if( gridComponent.isAnyColumnHidden() )
{
field = gridComponent.getColumnEditField("planStartDateTime");
if(field instanceof DateField)
{
DateField dField = (DateField) field;
ui.access(()->{
dField.setReadOnly(true);
ui.push();
dField.setReadOnly(false);
ui.push();
});
}
}
gridComponent.editItem(itemId);
selectedItem = gridComponent.getSelectedRow();
if( selectedItem == itemId )
{
;
}
}
}
}
Basically, I have to make the two problematic fields read only and then not read only to get around it, and since this is all happens in the browser, I have to use Push. Am I doing something wrong with Vaadin 7 Grid?
BTW, gridComponent.isAnyColumnHidden()
simply goes through all the columns in the grid to see if any are hidden. Very simple code inside my GridComponent
, which actually just wraps a Grid
with other components we want connected to our Grids.
Note that if the columns are NOT hidden, I have no problems. Also, I have the same problem whether I hide the columns programmatically or let the user hide columns.
This is an extremely complex situation, so the above is the easiest and shortest example I can give. Hopefully it is sufficient.
Thanks.