J'ai la table de cellules suivante. J'ai ajouté un bouton à chaque ligne. Quand on clique dessus, les nouvelles données doivent être mises à jour. Mais lorsque je clique sur Mettre à jour, les anciennes informations sur l'objet Contact sont passées à la méthode updateContact. Comment puis-je obtenir le texte modifié est entré par l'utilisateurBouton de mise à jour GWT Celltable
suivant est mon code:
public class CellTableExample implements EntryPoint {
/**
* A simple data type that represents a contact.
*/
private static class Contact {
private final String address;
private final Date birthday;
private final String name;
public Contact(String name, Date birthday, String address) {
this.name = name;
this.birthday = birthday;
this.address = address;
}
}
/**
* The list of data to display.
*/
@SuppressWarnings("deprecation")
private static final List<Contact> CONTACTS = Arrays.asList(
new Contact("John", new Date(80, 4, 12), "123 Abc Avenue"),
new Contact("Joe", new Date(85, 2, 22), "22 Lance Ln fasfasdfasfdasdfasfasdfasfasdfasfasfasdfasdfasdf"),
new Contact("Tom", new Date(85, 3, 22), "33 Lance Lnasdfasfdasdfffffffffffffffffff"),
new Contact("Jack", new Date(85, 4, 22), "44 Lance Lnsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"));
public void onModuleLoad() {
// Create a CellTable.
final CellTable<Contact> table = new CellTable<Contact>();
// Display 3 rows in one page
table.setPageSize(3);
// Add a text column to show the name.
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact object) {
return object.name;
}
};
table.addColumn(nameColumn, "Name");
// Add a date column to show the birthday.
DateCell dateCell = new DateCell();
Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
@Override
public Date getValue(Contact object) {
return object.birthday;
}
};
table.addColumn(dateColumn, "Birthday");
// Add a text column to show the address.
TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact object) {
return object.address;
}
};
table.addColumn(addressColumn, "Address");
ButtonCell updateButton= new ButtonCell();
Column <Contact,String> update= new Column <Contact,String>(updateButton)
{
@Override
public String getValue(Contact c)
{
return "Update";
}
};
update.setFieldUpdater(new FieldUpdater<Contact,String>()
{
@Override
public void update(int index, Contact c,String value)
{
SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
AsyncCallback callback = new AsyncCallback()
{
@Override
public void onFailure(Throwable caught)
{}
@Override
public void onSuccess(Object result)
{
}
};
service.updateContact(c.id, c.name, callback);
}
});
provider.addDataDisplay(table);
provider.updateRowCount(CONTACTS.size(), true);
SimplePager pager = new SimplePager();
pager.setDisplay(table);
VerticalPanel vp = new VerticalPanel();
vp.add(table);
vp.add(pager);
// Add it to the root panel.
RootPanel.get().add(vp);
}
}
trouvé la solution, tout ce que je devais faire était la suivante à chaque colonne:
colName.setFieldUpdater(new FieldUpdater<Contact,String>()
{
public void update(int index, Contact c, String value)
{
comp.name=value;
}
});