1 pièce(s) jointe(s)
store.load() : store.save() ?
Bonjour,
Mon application veut afficher des données dans une grid GXT (le code de base est disponible à cette adresse : http://www.extjs.com/examples/pages/grid/roweditor.html.
Je modifie donc juste ce code pour afficher des données qui proviennent d'une base de données.
Le problème est que le résultat est un tableau contenant 3 lignes (3 comme le nombre de tuples dans la BD) VIDES. Quand je regarde en DEBUG : - l'application ne passe jamais dans les getters des propriétés de FoodType (qui se trouve précisément dans Dictionary et IdentifiedDataModelObject).
- Les données contenues dans le store sont correctes
- La Gwt console ne retourne aucune erreur
Le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| public class FoodPanel extends LayoutContainer {
private ContentPanel foodPanel;
private CRCServiceAsync serviceAsync;
private AsyncCallback callBack;
List<ColumnConfig> configs;
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FlowLayout());
configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig();
column.setId("id");
column.setHeader("id");
column.setWidth(100);
TextField<String> text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
column = new ColumnConfig();
column.setId("locale");
column.setHeader("locale");
column.setWidth(100);
text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
column = new ColumnConfig();
column.setId("label");
column.setHeader("label");
column.setWidth(100);
text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
serviceAsync = GWT.create(CRCService.class);
final ListStore<FoodType> store = new ListStore<FoodType>();
callBack = new AsyncCallback<List<FoodType>>() {
public void onFailure(final Throwable throwable) {
System.out.println("failure");
}
public void onSuccess(List<FoodType> foodTypes) {
System.out.println("ok");
store.add(foodTypes);
ColumnModel cm = new ColumnModel(configs);
foodPanel = new ContentPanel();
foodPanel.setIcon(MyIcons.ICONS.food());
foodPanel.setHeading("Foods' list");
foodPanel.setFrame(true);
foodPanel.setHeight(600);
foodPanel.setWidth(600);
foodPanel.setLayout(new FitLayout());
final RowEditor<FoodType> re = new RowEditor<FoodType>();
final Grid<FoodType> grid = new Grid<FoodType>(store, cm);
grid.setBorders(true);
grid.addPlugin(re);
grid.setSize(300,600);
foodPanel.add(grid);
ToolBar toolBar = new ToolBar();
Button add = new Button("Ajouter une caractéristique d'aliment");
add.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
FoodType food = new FoodType();
re.stopEditing(false);
store.insert(food, 0);
re.startEditing(store.indexOf(food), true);
}
});
toolBar.add(add);
foodPanel.setTopComponent(toolBar);
foodPanel.setButtonAlign(Style.HorizontalAlignment.CENTER);
foodPanel.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
store.rejectChanges();
}
}));
foodPanel.addButton(new Button("Save", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
store.commitChanges();
}
}));
add(foodPanel);
}
};
serviceAsync.getAllFoodType(callBack);
}
public ContentPanel getPanel() {
return foodPanel;
}
public void setPanel(final ContentPanel foodPanel) {
this.foodPanel = foodPanel;
}
} |
La classe FoodType utilisée par le listStore ne comprend aucune propriété, elle étend simplement de dictionary
Code:
1 2
| public class FoodType extends Dictionary {
} |
La classe Dictionary comprend 2 propriétés et étends de IdentifiedDataModelObject
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public abstract class Dictionary extends IdentifiedDataModelObject {
protected String locale;
protected String label;
public String getLocale() {
return locale;
}
public void setLocale(final String locale) {
this.locale = locale;
}
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
} |
La classe IdentifiedDataModelObject contient un ID. C'est cette classe qui étends DataModelObject
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public abstract class IdentifiedDataModelObject extends BaseModelData implements DataModelObject {
protected Long id;
protected IdentifiedDataModelObject() {
id = null;
}
public Long getId() {
return id;
}
@Override
public boolean equals(final Object o) {
ApplicationUserType applicationUserType;
if (this == o) {
return true;
} else if (!(o instanceof ApplicationUserType)) {
return false;
} else {
applicationUserType = (ApplicationUserType) o;
if (id == null) {
return super.equals(o);
} else {
return id.equals(applicationUserType.getId());
}
}
}
@Override
public int hashCode() {
return id == null ? super.hashCode() : id.hashCode();
}
} |
Un service RPC me retourne donc une liste de foodType
Code:
1 2 3
| public List<FoodType> getAllFoodType() {
return foodTypeDao.getAll();
} |