Hi All! I'm new to GWT and I have a little problem. I'm trying to modify one of Google example apps - the dynamic table witch a school schedule. The data in the example is generated randomly. I modified it so the data in the table is from the JDO database. What I want to do is to modify the code, so the rows in the table will be updated when there is a change in the database, beacause right now they aren't updating. Here's the server side application code:
public class RankTableServiceImpl extends RemoteServiceServlet implements RankTableService { private static final Person[] NO_PEOPLE = new Person[0]; private static final int MAX_PEOPLE = 100; private final List<Person> people = new ArrayList<Person>(); Query query; List<User> results; PersistenceManager pm = PMF.get().getPersistenceManager(); public RankTableServiceImpl() { generateUserList(); } public Person[] getPeople(int startIndex, int maxCount) { int peopleCount = people.size(); int start = startIndex; if (start >= peopleCount) { return NO_PEOPLE; } int end = Math.min(startIndex + maxCount, peopleCount); if (start == end) { return NO_PEOPLE; } int resultCount = end - start; Person[] results = new Person[resultCount]; for (int from = start, to = 0; to < resultCount; ++from, ++to) { results[to] = people.get(from); } return results; } @Override protected void onAfterResponseSerialized(String serializedResponse) { System.out.println(serializedResponse); } private void generateUserList() { int i = 0; String login; String money; User element; int cash; query = pm.newQuery(User.class); results = (List<User>) query.execute(); Iterator<User> itr = results.iterator(); Collections.sort(results, new MoneyComparator()); while (i != results.size()) { if (i == MAX_PEOPLE) break; Person person = new Person(); person.setPosition(Integer.toString(i+1)); if(itr.hasNext()) { element = itr.next(); login = element.getLogin(); cash = element.getMoney(); money = Integer.toString(cash); } person.setLogin(login); person.setMoney(money); people.add(person); i++; } } } and the client side applicatin code: public class RankTableWidget extends Composite { public class RankProvider implements DynaTableDataProvider { private final RankTableServiceAsync rankService; private int lastMaxRows = -1; private Person[] lastPeople; private int lastStartRow = -1; public RankProvider() { rankService = (RankTableServiceAsync) GWT.create (RankTableService.class); ServiceDefTarget target = (ServiceDefTarget) rankService; String moduleRelativeURL = GWT.getModuleBaseURL() + "ranktable"; target.setServiceEntryPoint(moduleRelativeURL); } public void updateRowData(final int startRow, final int maxRows, final RowDataAcceptor acceptor) { if (startRow == lastStartRow) { if (maxRows == lastMaxRows) { pushResults(acceptor, startRow, lastPeople); return; } } rankService.getPeople(startRow, maxRows, new AsyncCallback<Person []>(){ public void onFailure(Throwable caught) { acceptor.failed(caught); } public void onSuccess(Person[] result) { lastStartRow = startRow; lastMaxRows = maxRows; lastPeople = result; pushResults(acceptor, startRow, result); } }); } private void pushResults(RowDataAcceptor acceptor, int startRow, Person[] people) { String[][] rows = new String[people.length][]; for (int i = 0, n = rows.length; i < n; i++) { Person person = people[i]; rows[i] = new String[3]; rows[i][0] = person.getPosition(); rows[i][1] = person.getLogin(); rows[i][2] = person.getMoney(); } acceptor.accept(startRow, rows); } } private final RankProvider rankProvider = new RankProvider(); private final DynaTableWidget dynaTable; public RankTableWidget(int visibleRows) { String[] columns = new String[] {"Position", "Nick", "Sum"}; String[] styles = new String[] {"pos", "nick", "sum"}; dynaTable = new DynaTableWidget(rankProvider, columns, styles, visibleRows); initWidget(dynaTable); } @Override protected void onLoad() { dynaTable.refresh(); } } Please tell me, how should I modify the code to make the table update? I think it's the matter of modifying the getPeople() function so I don't need to paste the rest of the code (correct me if I'm wrong) Regards, Przemek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~----------~----~----~----~------~----~------~--~---