Content
o GWT.create() method does the above magic by instantiating the service
o Here is it’s declaration to be place as part of the class declaration
o Here is it’s declaration to be place as part of the class declaration
private final SampleServiceAsync sampleService = GWT
.create(SampleService.class);
o Fix the import error
o After initializing the widgets, let us load the service
o Type the sampleService variable after the RootPanel.get().add(message);
statment
o Put a period after the variable
o Place cursor after period, enter: Ctrl+Space
o Select: getMessage(callback);
o There is the “callback” error, let’s put in the real implementation
o Delete the callback variable
o In between the paren, (), enter: new with a space
o Select: Ctrl+Space
o Select: AsyncCallback from popup
o Now the asynchronous sampleService is implemented without errors
o Type the sampleService variable after the RootPanel.get().add(message);
statment
o Put a period after the variable
o Place cursor after period, enter: Ctrl+Space
o Select: getMessage(callback);
o There is the “callback” error, let’s put in the real implementation
o Delete the callback variable
o In between the paren, (), enter: new with a space
o Select: Ctrl+Space
o Select: AsyncCallback from popup
o Now the asynchronous sampleService is implemented without errors
o In the onSuccess() method code body enter:
message.setText(“message goes here”);
o This will change the label message to what we
we desire, “message goes here”
o An error will appear, requesting that the message
variable should be final.
o Fix that error
message.setText(“message goes here”);
o This will change the label message to what we
we desire, “message goes here”
o An error will appear, requesting that the message
variable should be final.
o Fix that error
o In the onFailure() method code body enter:
Window.alert(“Error in executing RPC”);
o This will popup and error message in the browser
Window.alert(“Error in executing RPC”);
o This will popup and error message in the browser
o Change Label Message
Change the Label(“message goes here”);
to
new Label(“…..”);
o Since we are changing the message on the server side now
o We are good to go with this sample RPC code implementation.
Let us run this application
Change the Label(“message goes here”);
to
new Label(“…..”);
o Since we are changing the message on the server side now
o We are good to go with this sample RPC code implementation.
Let us run this application
o Here is the entry point code:
public class Sample implements EntryPoint {
private final SampleServiceAsync sampleService = GWT
.create(SampleService.class);
public void onModuleLoad() {
Label title = new Label("Title of Page");
title.setStyleName("title");
final Label message = new Label("......");
message.setStyleName("message");
RootPanel.get().add(title);
RootPanel.get().add(message);
sampleService.getMessage(new AsyncCallback() {
@Override
public void onSuccess(String result) {
message.setText(result);
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Error in executing RPC");
}
});
}
}