Java Reference
In-Depth Information
Listing 7-10. The code for DataServiceAsync
package com.appirio.timeentry.client;
import java.util.Vector;
import com.appirio.timeentry.client.TimeEntryData;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface DataServiceAsync {
void getProjects(AsyncCallback<String[]> callback);
void getMilestones(String project, AsyncCallback<String[]> callback);
void addEntries(Vector<TimeEntryData> entries, AsyncCallback<String>
callback);
void getEntries(AsyncCallback<Vector<TimeEntryData>> callback);
}
The first thing you need to do before you can start making RPC calls to your server is to
create an instance of the service proxy class. Add the following private class member to
your EntryPoint class, TimeEntry.java .
private final DataServiceAsync dataService = GWT.create(DataService.class);
With your dataService proxy defined you can start integrating your data from the
datastore into your client. Add the code in Listing 7-11 at the end of the addRow
method. This new code interacts with your server in two important ways. Whenever a
new row is added to the FlexTable , the getProjects method makes an RPC call to
fetch all of the projects from the server, and then populates the values in the picklist.
The inline AsyncCallback object contains two methods, onSuccess and onFailure , the
appropriate one of which is called depending on whether the RPC call succeeds or
fails.
The code also adds a listener to the Project picklist that detects changes in the
selected value. When a user selects a project from the picklist, the getMilestones RPC
RPC method is called and fetches the appropriate milestones. If the call succeeds, the
resulting milestones populate the values in the Milestone picklist and the seven time
input boxes are enabled for entry.
Listing 7-11. Code added to the addRow method in TimeEntry.java
// get all of the projects for the user
dataService.getProjects(new AsyncCallback<String[]>() {
public void onFailure(Throwable caught) {
handleError(caught);
 
Search WWH ::




Custom Search