Hi,
I'm evaluating SmartGWT. I made a sample application which retrieves data from server (via GWT RPC) and display them in a listgrid. And here is my problem because nothing appear in the listgrid but "No items to show" message.
Here is my code :
The main class (entryPoint) :
Listgrid widget :
Custom datasource :
Custom dataclass :
The POJO :
The GWT RPC service :
I can see through generated traces that data are retrieved from server and stored in my datasource instance (via setTestData() method).
The listgrid shows the rights fields as columns, from the datasource. But, it still keeps empty... no data on screen. Why ?
I must forget something, an obvious one, certainly !!!!
Thanks.
I'm evaluating SmartGWT. I made a sample application which retrieves data from server (via GWT RPC) and display them in a listgrid. And here is my problem because nothing appear in the listgrid but "No items to show" message.
Here is my code :
The main class (entryPoint) :
Code:
package fr.ct.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.smartgwt.client.widgets.layout.HLayout; import fr.ct.client.widget.WCTGrillePers; public class Principal implements EntryPoint { private HLayout mainLayout; public void onModuleLoad() { mainLayout = new HLayout(); mainLayout.setWidth100(); mainLayout.setHeight100(); affichePanneau(); } private void affichePanneau() { WCTGrillePers grillePers = new WCTGrillePers(); mainLayout.addMember(grillePers); mainLayout.draw(); } }
Code:
package fr.ct.client.widget; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.Autofit; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.LayoutSpacer; import com.smartgwt.client.widgets.layout.VLayout; import fr.ct.client.model.PersonneDS; public class WCTGrillePers extends Canvas { public WCTGrillePers() { final ListGrid grille = new ListGrid(); grille.setWidth(250); grille.setAlternateRecordStyles(true); grille.setShowAllRecords(true); // ListGridField matricule = new ListGridField("matricule", "Matricule", 60); // matricule.setType(ListGridFieldType.INTEGER); // ListGridField nom = new ListGridField("nom", "Nom", 80); // ListGridField prenom = new ListGridField("prenom", "Prenom", 80); // // grille.setFields(new ListGridField[] {matricule, nom, prenom}); grille.setCanResizeFields(true); grille.setCanReorderFields(true); grille.setCanSort(true); grille.setDataSource(PersonneDS.getInstance()); grille.setAutoFetchData(true); grille.setAutoFitData(Autofit.BOTH); grille.fetchData(); setShowResizeBar(true); setResizeBarTarget("next"); VLayout vlayout = new VLayout(); vlayout.setDefaultLayoutAlign(Alignment.CENTER); vlayout.addMember(new LayoutSpacer()); vlayout.addMember(grille); vlayout.addMember(new LayoutSpacer()); HLayout hlayout = new HLayout(); hlayout.setHeight100(); hlayout.setWidth100(); hlayout.setDefaultLayoutAlign(VerticalAlignment.CENTER); hlayout.addMember(new LayoutSpacer()); hlayout.addMember(vlayout); hlayout.addMember(new LayoutSpacer()); addChild(hlayout); } }
Code:
package fr.ct.client.model; import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.core.DataClass; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.fields.DataSourceDateField; import com.smartgwt.client.data.fields.DataSourceIntegerField; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.types.FieldType; import fr.ct.client.PersonnelService; import fr.ct.client.PersonnelServiceAsync; public class PersonneDS extends DataSource { private PersonnelServiceAsync service; private static PersonneDS instance = null; public static PersonneDS getInstance() { if (instance == null) { instance = new PersonneDS("personne_ds"); } // instance.fetchData(); return instance; } public PersonneDS(String id) { setID(id); DataSourceIntegerField matricule = new DataSourceIntegerField("matricule", "Matricule"); DataSourceTextField nom = new DataSourceTextField("nom", "Nom"); DataSourceTextField prenom = new DataSourceTextField("prenom", "Prenom"); DataSourceDateField dentr = new DataSourceDateField("dentr", "Entre le"); DataSourceDateField dmaj = new DataSourceDateField("dmaj", "Calcule au"); DataSourceTextField email = new DataSourceTextField("email", "Email"); setFields(matricule, nom, prenom, dentr, dmaj, email); setClientOnly(true); if (service == null) { service = (PersonnelServiceAsync)GWT.create(PersonnelService.class); } service.getPersonnes(new AsyncCallback<List<Personne>>() { public void onFailure(Throwable caught) { System.out.println("[ERREUR] Probleme de recuperation des personnes"); caught.printStackTrace(); } public void onSuccess(List<Personne> result) { PersonneDC[] donnees = new PersonneDC[result.size()]; int i = 0; for(Personne p : result) { donnees[i] = new PersonneDC(p.getMatricule(), p.getNom(), p.getPrenom(), p.getDentr(), p.getDmaj(), p.getEmail()); i++; } System.out.println("Recuperation des donnees en cours....."); setTestData(donnees); System.out.println("Nb personnes : " + donnees.length); for(PersonneDC p : donnees) { System.out.println(p.getMatricule() + "/" + p.getNom() + "/" + p.getPrenom()); } System.out.println("--------------------"); for(DataClass e : getTestData()) { System.out.println(e.getAttributeAsInt("matricule")+ "/" + e.getAttributeAsString("nom") + "/" + e.getAttributeAsString("prenom")); } System.out.println("Recuperation des donnees terminee."); } }); } }
Code:
package fr.ct.client.model; import java.util.Date; import com.smartgwt.client.core.DataClass; public class PersonneDC extends DataClass { public PersonneDC(Integer matricule, String nom, String prenom, Date dentr, Date dmaj, String email){ setAttribute("matricule", matricule); setAttribute("nom", nom); setAttribute("prenom", prenom); setAttribute("dentr", dentr); setAttribute("dmaj", dmaj); setAttribute("email", email); } public Integer getMatricule() { return getAttributeAsInt("matricule"); } public String getNom() { return getAttributeAsString("nom"); } public String getPrenom() { return getAttributeAsString("prenom"); } public Date getDentr() { return getAttributeAsDate("dentr"); } public Date getDmaj() { return getAttributeAsDate("dmaj"); } public String getEmail() { return getAttributeAsString("email"); } }
Code:
package fr.ct.client.model; import java.io.Serializable; import java.util.Date; public class Personne implements Serializable { private Integer matricule; private String nom; private String prenom; private Date dentr; private Date dmaj; private String email; public Personne() { } public Personne(Integer matricule, String nom, String prenom) { this.matricule = matricule; this.nom = nom; this.prenom = prenom; this.dentr = new Date(); this.dmaj = new Date(); this.email = ""; } public Personne(Integer matricule, String nom, String prenom, Date dentr, Date dmaj, String email) { this.matricule = matricule; this.nom = nom; this.prenom = prenom; this.dentr = dentr; this.dmaj = dmaj; this.email = email; } public void setEmail(String email) { this.email = email; } public void setDentr(Date dentr) { this.dentr = dentr; } public void setDmaj(Date dmaj) { this.dmaj = dmaj; } public Integer getMatricule() { return this.matricule; } public String getNom() { return this.nom; } public String getPrenom() { return this.prenom; } public Date getDentr() { return this.dentr; } public Date getDmaj() { return this.dmaj; } public String getEmail() { return this.email; } }
Code:
package fr.ct.client; import java.util.List; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import fr.ct.client.model.Personne; @RemoteServiceRelativePath("personnel") public interface PersonnelService extends RemoteService { public List<Personne> getPersonnes(); }
Code:
package fr.ct.client; import java.util.List; import fr.ct.client.model.Personne; import com.google.gwt.user.client.rpc.AsyncCallback; public interface PersonnelServiceAsync { public void getPersonnes(AsyncCallback<List<Personne>> callback); }
Code:
package fr.ct.server; import java.util.List; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import fr.ct.client.PersonnelService; import fr.ct.client.model.Personne; import fr.ct.server.model.TestData; public class PersonnelServiceImpl extends RemoteServiceServlet implements PersonnelService { /** * */ private static final long serialVersionUID = 1L; List<Personne> liste; public PersonnelServiceImpl() { liste = TestData.getPersonnes(); } public List<Personne> getPersonnes() { return liste; } }
The listgrid shows the rights fields as columns, from the datasource. But, it still keeps empty... no data on screen. Why ?
I must forget something, an obvious one, certainly !!!!
Thanks.
Comment