This seems like a simple task, but somewhere in searching the docs- I've missed the connection.
I have a menu stored in GAE and can return the results of a query:
public String[] getMeals() throws NotLoggedInException {
checkLoggedIn();
PersistenceManager pm = getPersistenceManager();
List<String> meals = new ArrayList<String>();
try {
Query q = pm.newQuery(Meal.class, "user == u");
q.declareParameters("com.google.appengine.api.users.User u");
q.setOrdering("createDate");
List<Meal> myMeals = (List<Meal>) q.execute(getUser());
for (Meal myMeal : myMeals) {
meals.add(myMeal.getMealID());
}
} finally {
pm.close();
}
return (String[]) meals.toArray(new String[0]);
}
With those results, I'd like to bind it to a FlexTable. Using the stockwatcher sample, I've managed to get my ID bound to the FlexTable, but am missing the concept of how I tie the other fields in my result set to it. (The fields I have in the GAE are mealID, mealType and mealDate)
From above, we can see that I'm tossing mealID into a List. I also know that my other fields must exist in the query because I haven't done anything to filter them. As a matter of fact, if I change my code to:
meals.Add(myMeal.getMealID(), myMeal.getMealType(), myMeal.getMealDate());
it returns all the data, but the flex table treats each item as a new row instead of the three fields on one row.
So my question is: how should I be capturing my records and sending them to my FlexTable so that I can bind the FlexTable to the resultset?
For reference, client side code:
private void loadMeals() {
// load meals from server service MealService
mealService.getMeals(new AsyncCallback<String[]>() {
public void onFailure(Throwable error) {
handleError(error);
}
public void onSuccess(String[] meals) {
displayMeals(meals);
}
});
}
private void displayMeals(String[] meals) {
for (String meal : meals) {
displayMenu(meal, meal, meal);
}
}
The flextable gets populated like this:
mealID | mealType | mealDate
1 | 1 | 1
2 | 2 | 2
3 | 3 | 3
I want it to populate like this:
mealID | mealType | mealDate
1 | Breakfast | 12/22/2012
2 | Lunch | 12/22/2012
3 | Snack | 12/23/2012
Thanks in advance for your input!