CellTable FieldUpdater Validation (not null, etc)

462 views
Skip to first unread message

bradr

unread,
Dec 4, 2010, 4:37:45 PM12/4/10
to Google Web Toolkit
I am using the CellTable, with the EditTextCell and the
DatePickerCell.

I'm trying to do some basic validation to control the users input. For
example
1) I'd like to prevent the user from inputting a null or empty string
in the EditTextCell
2) I have a Start and End date. And I want to make sure the user
doesn't set the End date before the Start date

finishColumn.setFieldUpdater(new FieldUpdater<Appointment, Date>() {
public void update(int index, Appointment object, Date value) {

if(object.getFinish().before(getStart()) {
Window.alert("The Appointment can
not finish before the Start date");
} else {
object.setFinish(value);
}
}
});

I'm able to prevent the incorrect finish date from being set, however,
the grid still displays the incorrect value. The object and grid are,
therefore, out of sync.

What is the recommended way to data validation within in editable
CellTable?

John LaBanca

unread,
Dec 5, 2010, 9:49:19 PM12/5/10
to google-we...@googlegroups.com
DateCell and EditTextCell store user entered data in a view data object, so the pending user entered value can be rendered even if the table is refreshed.  To clear it, do the following:
myDateCell.clearViewData(keyOfAppointment);

If you specified a key provider to CellTable, the key is the key provided by it.  If you do not use a key provider, the key is the Appointment itself.

Thanks,
John LaBanca
jlab...@google.com



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Denny Kluge

unread,
Feb 26, 2016, 5:10:51 AM2/26/16
to GWT Users
I had to call refresh on the DataProvider for the grid to display the previous value.

tColName.setFieldUpdater(new FieldUpdater<MyModel, String>() {
   
public void update(int index, final MyModel model, final String newValue) {
     
if (newValue == null || newValue.trim().isEmpty()) {
         textCellName
.clearViewData(model);
         mDataProvider
.refresh();
         return;
      }
   
}
}




Reply all
Reply to author
Forward
0 new messages