Hi , I'm trying to retreive data fro Data base and put it in a GXT grid , but the problem is that the grid shows wrong values (same value )
help please !
here's my code :
----------------------------------------------------------------------------------
package org.gonevertical.demo.client;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class BoitierInfoWidget extends LayoutContainer {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("padding", "20px");
// gwt service
final RpcCallServiceAsync rpc = (RpcCallServiceAsync) GWT.create(RpcCallService.class);
// proxy and reader
RpcProxy<List<Boitier>> proxy = new RpcProxy<List<Boitier>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<Boitier>> callback) {
rpc.BoitierInfo(callback);
}
};
BeanModelReader reader = new BeanModelReader();
// loader and store
ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
loader.load();
// column model
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("id", "Id", 200));
columns.add(new ColumnConfig("mob", "Mob", 100));
columns.add(new ColumnConfig("date", "Date", 50));
ColumnModel cm = new ColumnModel(columns);
Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
ContentPanel panel = new ContentPanel();
panel.setHeading("BeanModel Grid Example");
panel.setSize(400, 200);
panel.setLayout(new FitLayout());
panel.add(grid);
add(panel);
}
}
------------------------------------------------------------------------------------
public class DemoMySqlConn implements EntryPoint {
@Override
public void onModuleLoad() {
RootPanel.get().add(new BoitierInfoWidget());
}}
-----------------------------------------------------------------------------------
package org.gonevertical.demo.client;
import java.io.Serializable;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* I use this class to store my mysql recordset in an object that is an array.
* This will give an example of how I pass data from the server to client in an object,
* one of my favourites for its simplicity.
*
* @author branflake2267
*
*/
public class Boitier implements Serializable {
private int id ;
private int mob ;
private String Date ;
public Boitier() {
}
/**
*
*/
public Boitier(int id, int mob , String Date) {
this.id = id;
this.mob = mob;
this.Date = Date;
}
// fields to store and transfer data
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getMob() {
return mob;
}
public void setMob(int mob) {
this.mob = mob;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
Date = date;
}
}
------------------------------------------------------------------------------
package org.gonevertical.demo.client;
import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;
@ BEAN (Boitier.class)
public interface BoitierBeanModel extends BeanModelMarker {
}
------------------------------------------------------------------------------------------
public List<Boitier> BoitierInfo(){
ArrayList <Boitier> v=new ArrayList<Boitier> ();
Boitier b=new Boitier();
Connection connection = getConn();
System.out.println("v vide: "+v.isEmpty());
String query = "SELECT id,mob,Date FROM b125;";
try{
int lsize= v.size();
Statement select = connection.createStatement();
ResultSet result = select.executeQuery(query);
while (result.next()){
b.setId(result.getInt(1));
int x = b.getId();
b.setMob(result.getInt(2));
int y = b.getMob();
b.setDate(result.getString(3));
v.add(b);
// System.out.println("la liste est"+ v.get(i));
}
}
catch (SQLException exx){
System.out.println("La sélection de toutes les personnes a échoué");
}
return v;
}
-----------------------------------------------------------------------------------------------------------------------
RpcCallServiceImpl.java
@SuppressWarnings("serial")
public class RpcCallServiceImpl extends RemoteServiceServlet implements RpcCallService {
/**
* get the books of the bible and info in an object array
* This is my favorite way to get recordset data
*
* @return bibleData (array)
*/
DB_Boitier db = new DB_Boitier();
public List<Boitier> BoitierInfo() {
List<Boitier> lb = db.BoitierInfo();
return lb;
}
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/rcPT0OtdynMJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment