Hello everybody) I've got a problem with server side in my tutorial project on GWT. When I run my Eclipse project as web application without server side(I simple comment SERVER SIDE block and discomment NO SERVER SIDE one in onModuleLoad method of FstGWTProject class) everything is OK, but when I'am trying to run it with server side it doesnt show anything in browser. I run it from Eclipse as Web Application and then I go to http://127.0.0.1:8888/FstGWTProject.html. Jetty App Server is used by default.
-- I've created a simple RPC interface(both IRPCClient and IRPCClientAsync) as following:
After this I've implemented IRPCClient:
package ua.xander.fg.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("service")
public interface IRPCClient extends RemoteService
{
public String sayHallo(String name);
public int multiplyThem(int x1, int x2);
public int getID();
}
and
package ua.xander.fg.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface IRPCClientAsync {
public void sayHallo(String name, AsyncCallback ac);
public void multiplyThem(int x1, int x2, AsyncCallback ac);
public void getID(AsyncCallback ac);
}
After this I've implemented IRPCClient:
package ua.xander.fg.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import ua.xander.fg.client.IRPCClient;
public class RPCServerImpl extends RemoteServiceServlet implements IRPCClient{
private int ID = 0;
@Override
public String sayHallo(String name) {
// TODO Auto-generated method stub
return "Greetings " + name;
}
@Override
public int multiplyThem(int x1, int x2) {
// TODO Auto-generated method stub
return x1 * x2;
}
@Override
public int getID() {
// TODO Auto-generated method stub
return ID++;
}
}Then I've created a simple GUI layout. I've implemented only sayHallo method
package ua.xander.fg.client;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
public class MainGUI extends HorizontalPanel implements IClient{
private IRPCClientAsync service;
private TextBox halloName;
private Label halloLbl;
private Button halloBtn;
private TextBox x1Txt;
private TextBox x2Txt;
private Button multBtn;
private Label idLbl;
private Button idBtn;
public MainGUI(String url)
{
set_service(url);
set_gui();
}
private void set_service(String url)
{
System.out.println(url);
this.service = GWT.create(IRPCClient.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
endpoint.setServiceEntryPoint(url);
}
private void set_gui()
{
VerticalPanel halloPanel = new VerticalPanel();
VerticalPanel multPanel = new VerticalPanel();
VerticalPanel idPanel = new VerticalPanel();
//===================Hallo Panel==================================
halloName = new TextBox();
halloLbl = new Label();
halloBtn = new Button("Say Hallo");
halloBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
//MainGUI.this.sayHallo(halloName.getText());
}
});
halloPanel.add(halloPanel);
halloPanel.add(halloLbl);
halloPanel.add(halloBtn);
//========================Mult Panel==============================
//========================ID Panel==============================
this.add(halloPanel);
}
@Override
public void sayHallo(String name) {
this.service.sayHallo(name, new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
halloLbl.setText("FAILURE OCCURED");
}
@Override
public void onSuccess(Object result) {
if(!(result instanceof String)) {return;}
halloLbl.setText((String) result);
}
});
}
@Override
public void multiplyThem(int x1, int x2) {
// TODO Auto-generated method stub
}
@Override
public void getID() {
// TODO Auto-generated method stub
}
}And surely:
package ua.xander.fg.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class FstGWTProject implements EntryPoint {
public void onModuleLoad() {
//NO SERVER SIDE
/*VerticalPanel vp = new VerticalPanel();
Button btn = new Button("HALLO");
vp.add(btn);
RootPanel.get().add(vp);*/
//SERVER SIDE MainGUI gui = new MainGUI(GWT.getModuleBaseURL() + "service");
RootPanel.get().add(gui);
}
}web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>RPCServlet</servlet-name>
<servlet-class>ua.xander.fg.server.RPCServerImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RPCServlet</servlet-name>
<url-pattern>/fstgwtproject/service</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>FstGWTProject.html</welcome-file>
</welcome-file-list>
</web-app>I would appreciate any suggestions. Thank You)
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment