java - How to get row values from dynamic FlexTable in GWT? -
i'm trying develope application creates flex table dynamically database jdbc. want implement 2 methods, 1 update row values , 1 delete current row inserting 2 buttons per row. problem can't current row values.
fishtable method creates flextable
public void fishtable(){ if(service == null){ service = gwt.create(service.class); } service.getfishes(fishtablecallback); }
asynccallback fishtablecallback = new asynccallback(){
@override public void onfailure(throwable caught) { string details = caught.getmessage(); system.out.println(details); } @override public void onsuccess(fishtable result) { table.removeallrows(); tablepanel.clear(); table.settext(0, 0, "id"); table.settext(0, 1, "fish"); table.settext(0, 2, "price"); table.setcellpadding(6); table.getcellformatter().addstylename(0, 0, "header1_3"); table.getcellformatter().addstylename(0, 1, "header2"); table.getcellformatter().addstylename(0, 2, "header1_3"); tablepanel.add(table); (int = 0; < result.getidarray().length; i++) { button updatebtn = new button("update"); button deletebtn = new button("delete"); id = new textbox(); id.settext(result.getidarray()[i]); id.addstylename("fishid"); id.setreadonly(true); name = new textbox(); name.settext(result.getnamearray()[i]); price = new textbox(); price.settext(result.getpricearray()[i]); price.addstylename("fishid"); int row = table.getrowcount(); table.setwidget(row, 0, id); table.setwidget(row, 1, name); table.setwidget(row, 2, price); table.setwidget(row, 3, updatebtn); table.setwidget(row, 4, deletebtn); updatebtn.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { updatefish(id.gettext() , name.gettext() , price.gettext()); } }); deletebtn.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { index = table.getcellforevent(event).getrowindex()-1; deletefish(table.gettext(index, 0)); } }); } } };
code inside updatebtn handler doesn't work, takes values last row. tried index = table.getcellforevent(event).getrowindex()-1 current row can't value of column 0 inside updatebtn handler. want send these values database. how values row click these buttons?
updatefish , deletefish methods:
public void deletefish(string id){ if(service == null){ service = gwt.create(service.class); } service.deletefish(id, deletefishcallback); } public void updatefish(string fishid , string fishname , string fishprice){ if(service == null){ service = gwt.create(service.class); } service.updatefish(fishid , fishname , fishprice , updatefishcallback); } asynccallback<deletefish> deletefishcallback = new asynccallback<deletefish>() { @override public void onsuccess(deletefish result) { fishtable(); } @override public void onfailure(throwable caught) { string details = caught.getmessage(); system.out.println(details); } }; asynccallback<updatefish> updatefishcallback = new asynccallback<updatefish>() { @override public void onsuccess(updatefish result) { fishtable(); } @override public void onfailure(throwable caught) { string details = caught.getmessage(); system.out.println(details); } };
replace
int row = table.getrowcount();
with
final int row = table.getrowcount();
and do
deletebtn.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { textbox tb = (textbox) table.getwidget(row - 1, 0); deletefish(tb.gettext()); } });
Comments
Post a Comment