public interface ServletServiceInterface extends RemoteService {
public String getTheStringReverse(String StringToServer);
}
In this we will define the same method as defined in ServletServiceInterface,But we will also define a argument called AsyncCallback which identifies as a callback method
public interface ServletServiceInterfaceAsync {
public void getTheStringReverse(String StringToServer,AsyncCallback callback);
}
public class ServletServiceInterfaceImpl extends RemoteServiceServlet implements ServletServiceInterface {
private static final long serialVersionUID = 1L;
public String getTheStringReverse(String StringToServer) {
StringBuffer buffer=new StringBuffer(StringToServer);
return buffer.reverse().toString();
one important we need to do is to define the path of the rpc implementation class in gwt.xml file as
<servlet path= "/server/callback " class="com.example.server.ServletServiceInterfaceImpl"/ >
now from the onModuleLoad() , u can call as
private String StringToServer;
private ServletServiceInterfaceAsync asyncCallback;
private AsyncCallback callback ;
private HorizontalPanel hPanel;
public void onModuleLoad() {
asyncCallback=(ServletServiceInterfaceAsync)GWT.create(ServletServiceInterface.class);
((ServiceDefTarget)asyncCallback).setServiceEntryPoint(GWT.getModuleBaseURL()+"/server/callback");
callback =new AsyncCallback() {
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
public void onSuccess(Object result) {
((TextBox)hPanel.getWidget(hPanel.getWidgetCount-2)).setText(result.toString());
}
};
hPanel=new HorizontalPanel();
hPanel.add(new TextBox());
hPanel.add(new Button("Get String Reverse",new ClickListener() {
public void onClick(Widget sender) {
StringToServer=((TextBox)hPanel.getWidget(hPanel.getWidgetCount()-2)).getText();
asyncCallback.getTheStringReverse(StringToServer, callback);
}
}));
RootPanel.get().add(hPanel);
}//OnModuleLoad () Close
No comments :
Post a Comment