Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg
package com.mts.myapp.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class MyApp implements EntryPoint {
private Label labelMessage;
private Button clickMeButton;
private SampleServiceAsync serviceProxy;
public Label getLabelMessage() {
return labelMessage;
}
public void onModuleLoad() {
GWT.log("Starting MyApp test app...", null);
RootPanel rootPanel = RootPanel.get();
final AbsolutePanel absolutePanel = new AbsolutePanel();
rootPanel.add(absolutePanel, 5, 5);
absolutePanel.setSize("335px", "205px");
clickMeButton = new Button();
absolutePanel.add(clickMeButton, 0, 42);
clickMeButton.setText("Click me!");
clickMeButton.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
GWT.log("OnClick event on button", null);
serviceProxy = (SampleServiceAsync) GWT
.create(SampleService.class);
String serviceUrl = GWT.getModuleBaseURL() + "SampleService";
if (GWT.isScript()) {
serviceUrl = "/SampleService";
}
((ServiceDefTarget) serviceProxy)
.setServiceEntryPoint(serviceUrl);
callSendMessage();
}
});
labelMessage = new Label("No message yet...");
absolutePanel.add(labelMessage);
}
private void callSendMessage() {
AsyncCallback callback = new AsyncCallback() {
public void onFailure(Throwable caught) {
Window.alert("This call failed on the client!");
}
public void onSuccess(Object result) {
GWT.log("RPC success", null);
Window.alert("This call should be succeeding!");
Label message = getLabelMessage();
message.setText(result.toString());
}
};
GWT.log("Service called on proxy...", null);
serviceProxy.echo("I hope this work!", callback);
}
}
package com.mts.myapp.server;
import org.apache.log4j.Logger;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mts.myapp.client.MyApp;
import com.mts.myapp.client.SampleService;
import com.google.gwt.core.client.GWT;
public class SampleServiceImpl extends RemoteServiceServlet implements SampleService {
static Logger logger = Logger.getLogger(MyApp.class);
private static final long serialVersionUID = 1L;
public String echo(String message) {
logger.debug("Sending a response...");
GWT.log("Sending response...", null);
return "It sure did!!!!";
}
}
package com.mts.myapp.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
public interface SampleService extends RemoteService {
/**
* Utility class for simplifying access to the instance of async service.
*/
public static class Util {
private static SampleServiceAsync instance;
public static SampleServiceAsync getInstance(){
if (instance == null) {
instance = (SampleServiceAsync) GWT.create(SampleService.class);
ServiceDefTarget target = (ServiceDefTarget) instance;
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "SampleServiceImpl");
}
return instance;
}
}
public String echo(String message);
}
package com.mts.myapp.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface SampleServiceAsync {
public void echo(String message, AsyncCallback callback);
}
<module>
<inherits name="com.google.gwt.user.User"/>
<entry-point class="com.mts.myapp.client.MyApp"/>
<servlet path="/SampleService" class="com.mts.myapp.server.SampleServiceImpl"/>
</module>
private SampleServiceAsync serviceProxy = SampleService.Util.getInstance();
jcmorris-mts wrote:How can one manually override the way that Designer automatically creates the build.xml file when one deploys a module?
Users browsing this forum: No registered users and 3 guests