Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What to understand:
Server
(Browser)
(Tomcat)
StringReverser Code
1. Declare the Async object
private StringReverserServiceAsync reverserService = null;
3. Set the Async Entry Point to the server class via URL
//this just gets the Url (eg. http://ahs510.org) String module = GWT.getHostPageBaseURL(); int indexMod = module.indexOf(GWT.getModuleName()); String host = module.substring(0, indexMod); //this sets the entry point for the service back to server ((ServiceDefTarget)reverserService).setServiceEntryPoint( host + "/servlet/StringReverserService");
StringReverser Code
4. Call reverseString and define the AsynCallBack onSuccess and OnFailure
reverserService.reverseString(stringToReverse, new AsyncCallback() { public void onFailure(Throwable caught) { // Reset the button text and remove the loading animation resetWiget(); Window.alert("Fail to get response from server: "); } public void onSuccess(Object result) { // Reset the button text and remove the loading animation resetWiget(); // Get the service call response and display it String reverse = (String) result; ReversedStringDisplayDialog dlg = new ReversedStringDisplayDialog(stringToReverse, reverse); dlg.show(); } });
public String reverseString(String stringToReverse) { StringBuffer reverse = new StringBuffer(stringToReverse.length()); for (int i = (stringToReverse.length() - 1); i >= 0;i--) reverse.append(stringToReverse.charAt(i)); return reverse.toString(); } }
In review
1. Configure Client side files:
a. StringReverserService
b. StringReverserServiceAsyc c. EntryPoint class: StringReverser
Instructions: A simple text box and button to check is entry a palindrome. Display results to user