I am trying to make a sample code for my further work. I am using gwt vanillia and new to gwt. My purpose is to populate some textboxes and a grid. for populating textboxes from database, no problem with rpc call. But I could’nt populate datagrid via using RPC call. I used Bastian Tenbergen’s tutorial
for populating some textboxes. But when i tried to populate the grid with asyncronious callback using ArrayList, code failed. I know ArrayList is also serializable but I can’t solve the issue.
Any advice is appreciated.
Here is some code for my questin.
In server package: SqlDbConnection.java
public ArrayList<hastaGrid> callGrid(String something){
ArrayList<hastaGrid> list = new ArrayList<hastaGrid>();
hastagrid hastaGrid = null;
try {
Statement st = conn.createStatement();
ResultSet result = st.executeQuery("select name from TEST where name = '"+ something +"'");
while(result.next()) {
hastagrid = new hastaGrid(result.getString(1), result.getString(2),result.getNString(2),result.getString(3));
list.add(hastaGrid);
System.out.println("result: " +hastagrid.getLogin().toString()+" " + hastagrid.getPassword() +" "+ hastagrid.getName() +" " + hastagrid.getSurname());
}
result.close();
st.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
In client package: hastaGrid.java //the class also have getter and setter methods.
public class hastaGrid implements IsSerializable {
private String name;
private String surname;
private String login;
private String password;
public hastaGrid(String name,String surname, String login, String password){
this.setName(name);
this.setSurname(surname);
this.setLogin(login);
this.setPassword(password);
}}
In client package: DBConnection.java
public interface DBConnection extends RemoteService {
public ArrayList<hastaGrid> callGrid(String name); }
In client package: DBConnectionAsync.java
public interface DBConnectionAsync {
public void callGrid(String name, AsyncCallback<ArrayList<hastaGrid>> callback); }
In client package: userDetail.java
onModuleLoad() {
AsyncCallback> callback = new AuthenticationHandler1();
rpc.gridGetir(“John”,callback);
}
private class AuthenticationHandler<T> implements AsyncCallback<ArrayList<hastaGrid>> {
public void onFailure(Throwable ex) {
RootPanel.get().add(new HTML("RPC call failed"));
}
public void onSuccess(ArrayList<hastaGrid> result) {
result.get(0).getName(); } } // I just want to reach some result here when debugging.
I read lots of pages on web but can’t find a specific solution. I could be wrong. Thanks for responses.
First you should make sure that your RPC returns the appropriate List of hastaGrid objects – and please do capitalize the class name 🙂
I use the
AsyncDataProvidermodel quite a lot with variousDataGridimplementations and create an implementing class somewhat like the following:In your DataGrid initalization code you put:
This approach works best if you also add a pager, because the dataprovider listens to range changes, triggered by clicking the pager.
Hope this helps!