GWTページ表示処理:RPC呼び出し

1348 ワード


public class DemoClient implements EntryPoint {

public void onModuleLoad() {
final SampleServiceAsync sampleService = (SampleServiceAsync) 
GWT.create(SampleService.class);
        ServiceDefTarget target = (ServiceDefTarget)sampleService;
         String staticResponseURL = GWT.getModuleBaseURL();
        staticResponseURL += "/getStringService";
         target.setServiceEntryPoint(staticResponseURL);
        
         final Label label = new Label();
         final Button button = new Button("Get String");
        
         button.addClickListener(new ClickListener() {
             public void onClick(Widget sender) {
                sampleService.getString(new AsyncCallback() {
                     public void onSuccess(Object result) {
                         label.setText((String) result);
                     }
                     public void onFailure(Throwable caught) {
                         label.setText(caught.getMessage());
                    }
                 });
             }
         });

         RootPanel.get("1").add(button);
         RootPanel.get("2").add(label);
     }
}