2014-11-06 50 views
0

我有以下CellTable CellTableGWT CellTable:如何更新文本框动态

当用户点击薪酬最小值。复选框,它应该将立即到期列的值复制到立即支付文本字段并重新计算现在支付日期列的值。

下面是CheckboxCell代码和TextInputCell收费今天)列(收费敏):

private Column<AccountInvoice, Boolean> buildPayMin() { 

    columnPayMin = new Column<AccountInvoice, Boolean>(new CheckboxCell(true, false)) { 
     @Override 
     public Boolean getValue(AccountInvoice object) { 
      return object.isPayMinimum(); 
     } 

     @Override 
     public void onBrowserEvent(Context context, Element elem, AccountInvoice object, NativeEvent event){ 

      // Get event type 
      int eventType = Event.as(event).getTypeInt(); 

      // See if this is a 'change' event 
      if (eventType == Event.ONCHANGE) { 

       String value = columnMinDue.getValue(object); 

       // Get the cell to copy the value from     
       TextInputCell cell = (TextInputCell) columnPayToday.getCell(); 
       // Re-create the view data for the cell 
       TextInputCell.ViewData viewData = new TextInputCell.ViewData(value); 
       cell.setViewData(object, viewData); 
       // Refresh 
       cellTable.redraw(); 

       event.preventDefault(); 
       event.stopPropagation(); 
      } 
     } 
    }; 
    columnPayMin.setDataStoreName(columnPayMinHeader); 
    columnPayMin.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); 
    columnPayMin.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); 
    return columnPayMin; 
} 

// ----------------------------------------------------------- 

private Column<AccountInvoice, String> buildPayToday() { 
    columnPayToday = new Column<AccountInvoice, String>(new TextInputCell()) { 
     @Override 
     public String getValue(AccountInvoice object) { 
      return object.getPaymentAmount(); 
     } 
    }; 
    columnPayToday.setDataStoreName(columnPayTodayHeader); 
    columnPayToday.setFieldUpdater(new FieldUpdater<AccountInvoice, String>() { 
     @Override 
     public void update(int index, AccountInvoice object, String value) { 
      object.setPaymentAmount(value); 
      cellTable.redraw(); 
     } 
    }); 
    return columnPayToday; 
} 

我能得到的值复制过来,但总共为今日薪酬列不刷新。它似乎只在手动输入值为付款日期文本字段时刷新。我甚至尝试过:

columnPayToday.getFieldUpdater().update(context.getIndex(), object, value); 

哪一个也没有帮助。

感谢您提供的任何帮助。

回答

2

ViewData表示TextInputCell中的临时值。当您调用cellTable.redraw()时,TextInputCell将恢复为原始值(该列的方法getValue())。

如果您只想修改TextInputCell的“视图”状态,或者调用accountInvoice.setPayToday#(或其他任何方法)来更新对象,然后调用ListDataProvider上的refresh(),则不要重绘表格与重绘相比,更有效地更新表格)。

+0

谢谢您的回复。 请参阅我如何根据您的建议修改代码:http://pastebin.com/Z4bQYrzf 不幸的是,它仍然无法正常工作。 ***'Window.alert' ***只会触发其中一个,不知何故会触发它,并杀死它,即使再次选中该复选框也不会触发。我也决定使用*** FieldUpdater ***代替*** onBrowserEvent ***,它没有效果,但代码更短。 – user1576840 2014-11-06 04:52:26

+1

您仍然调用'cellTable.redraw()' - 这次是在另一列的FieldUpdater中。你可怜的桌子一直在重绘!你几乎不应该在代码中的任何地方调用redraw()。 – 2014-11-06 05:00:43

+0

谢谢!我解决了这个问题,现在它工作得很漂亮! – user1576840 2014-11-06 14:46:35