Thursday, October 2, 2014

Using datagrid.redrawRow after failed cell validation

I'm updating a double value in a datagrid to using a custom parser on an EditTextCell.  If the parser throws an error, then I'm trying to put the original value back by redrawing the row.  But, the erroneous value stays in place.  Stepping through the code, I do see it going through HasDataPresenter's setRowData method, and even see the original value in the row object.  But, that value doesn't get drawn.

If I now click on the cell again, then click away without editing, then the original value does get written into the cell.  That led me to try a deferred command, which didn't work, hence code below with a ridiculous delay before redrawing (which, needless to say, also doesn't work).

If it makes any difference, I'm using a SingleSelectionModel.

Am I doing something wrong here?  Or is there a better way to check the values as they're being entered?

          @Override
          public void update(final int index, R item, String value)
          {
             double doubleValue = 0.0;
             boolean needsRedraw = false;
             try
             {
                 if (value != null && !value.isEmpty())
                 {
                     doubleValue = MyFormat.PARSER.parse(value);
                     needsRedraw = true;  // added
                 }
                 item.setAmt(doubleValue);
                 thisCell.clearViewData(item);
             }
             catch(Exception e)
             {
                needsRedraw = true;
             }
             if (needsRedraw)
             {
                //grid.redrawRow(index);
                Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
                   public boolean execute() {
                      grid.redrawRow(index);
                      return false;
                   }
                }, 1000);
               
             }
          }
       });

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment