1 pjaol 1.2 /*******************************************************************************
2 * Copyright (c) 2005, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
|
11 pjaol 1.1 package com.pjaol.client;
12
13 import com.google.gwt.core.client.EntryPoint;
14 import com.google.gwt.core.client.GWT;
15 import com.google.gwt.user.client.rpc.AsyncCallback;
16 import com.google.gwt.user.client.rpc.ServiceDefTarget;
17 import com.google.gwt.user.client.ui.Button;
18 import com.google.gwt.user.client.ui.ClickListener;
19 import com.google.gwt.user.client.ui.Label;
20 import com.google.gwt.user.client.ui.RootPanel;
21 import com.google.gwt.user.client.ui.Widget;
22
23 /**
24 * Entry point classes define <code>onModuleLoad()</code>.
25 */
26 public class test implements EntryPoint {
27
28 /**
29 * This is the entry point method.
30 */
31 public void onModuleLoad() {
32 pjaol 1.1 final Button button = new Button("Click me");
33 final Label label = new Label();
34
35 button.addClickListener(new ClickListener() {
36 public void onClick(Widget sender) {
37 if (label.getText().equals(""))
38 //label.setText("Hello World!");
39 getMyId("fish food", label);
40 else
41 label.setText("");
42 }
43 });
44
45 // Assume that the host HTML has elements defined whose
46 // IDs are "slot1", "slot2". In a real app, you probably would not want
47 // to hard-code IDs. Instead, you could, for example, search for all
48 // elements with a particular CSS class and replace them with widgets.
49 //
50 RootPanel.get("slot1").add(button);
51 RootPanel.get("slot2").add(label);
52 }
53 pjaol 1.1
54
55 public void getMyId (String s , final Label label) {
56
57 TestGWTAsync service = (TestGWTAsync) GWT.create(TestGWT.class);
58 ServiceDefTarget endPoint = (ServiceDefTarget)service;
59 String moduleRelativeURL = GWT.getModuleBaseURL() + "/testGWT";
60 endPoint.setServiceEntryPoint(moduleRelativeURL);
61
62
63 AsyncCallback callback = new AsyncCallback() {
64 public void onSuccess(Object result) {
65 label.setText((String) result);
66 }
67
68 public void onFailure(Throwable caught) {
69 label.setText("nope :-(");
70 }
71 };
72 service.getReturnId("fish food", callback);
73 }
74 pjaol 1.1 }
|