Hi all
I use a Table component. I set a Property.ValueChangeListener on each TextField in the Table (with setImmediate=true). The listener calculates the sum of each field in the row and store it in a generated column called “Total”. The listener calculates also the footer balance for each column.
My problem : when I select a cell, change the value and press Tab, I lose the focus on the next cell and I had to focus manually a second time.
The listener of each TextFields of the table :
final Property.ValueChangeListener listener = new Property.ValueChangeListener() {
public void valueChange(Property.ValueChangeEvent event) {
double sum = 0;
BudgetFormDTO budget = (BudgetFormDTO) ((TextField) event
.getProperty()).getData();
sum = budget.getInitialization() + budget.getConception()
+ budget.getImplementation() + budget.getIntroduction();
for (int i = 0; i < totals.size(); i++)
if (totals.get(i).getData().equals(budget))
totals.get(i).setValue(sum);
// Footer
calculateFooter();
}
};
INFO: The “budget” variable is the beanItem of the row.
INFO: If I comment the line “calculateFooter();”, I haven’t this problem and the next cell is correctly focused with Tab key.
The calculateFooter() method :
protected void calculateFooter() {
Double balance=0.0;
Double totalBalance=0.0;
// Footer "name"
this.setColumnFooter("name", "Solde");
// Footer "initialization"
balance = calculateSolde(budgetMandate.getInitialization(), budgetRevised.getInitialization(),
budgetSpent.getInitialization(), budgetEngaged.getInitialization());
totalBalance += balance;
this.setColumnFooter("initialization", String.valueOf(balance));
// Footer "conception"
balance = calculateSolde(budgetMandate.getConception(), budgetRevised.getConception(),
budgetSpent.getConception(), budgetEngaged.getConception());
totalBalance += balance;
this.setColumnFooter("conception", String.valueOf(balance));
// Footer "implementation"
balance = calculateSolde(budgetMandate.getImplementation(), budgetRevised.getImplementation(),
budgetSpent.getImplementation(), budgetEngaged.getImplementation());
totalBalance += balance;
this.setColumnFooter("implementation", String.valueOf(balance));
// Footer "introduction"
balance = calculateSolde(budgetMandate.getIntroduction(), budgetRevised.getIntroduction(),
budgetSpent.getIntroduction(), budgetEngaged.getIntroduction());
totalBalance += balance;
this.setColumnFooter("introduction", String.valueOf(balance));
// Footer "total"
this.setColumnFooter(BUDGET_TOTAL_COLUMNNAME, String.valueOf(totalBalance));
}
The TotalColumnGenerator inner class :
class TotalColumnGenerator implements Table.ColumnGenerator {
private static final long serialVersionUID = -3307604339645408677L;
private List<Label> totals;
public TotalColumnGenerator(List<Label> totals) {
this.totals = totals;
}
public Component generateCell(Table source, Object itemId,
Object columnId) {
if (columnId.equals(BUDGET_TOTAL_COLUMNNAME)) {
Label ltemp = new Label();
ltemp.setWidth("100%");
BudgetFormDTO budget = (BudgetFormDTO) itemId;
ltemp.setData(budget);
totals.add(ltemp);
if (budget != null)
ltemp.setValue(budget.getInitialization()
+ budget.getConception()
+ budget.getImplementation()
+ budget.getIntroduction());
return ltemp;
}
return null;
}
}
So I think I can find a workaround but I need your opinion before that.
Thank you in advance.
Best regards,
Jachen.