Я изучаю GWT, и в настоящее время я борюсь с RPC. У меня есть простой проект: ярлык, текстовое поле, выходная метка и кнопка. Я хочу, когда пользователь вводит свое имя в текстовое поле и нажимает кнопку «Отправить», он получит сообщение с сервера «Привет» + имя + «Здесь говорит сервер» - глупый пример. Однако в моем КЛИЕНТ у меня есть графический интерфейс пакета и пакета услуг и мой класс EntrypointGWT Невозможно прочитать свойство 'example' of undefined
public class TestGwt270 implements EntryPoint {
public void onModuleLoad()
{
TestGwt270ClientImpl clientImpls = new TestGwt270ClientImpl("/TestGwt270/testgwt270service");
GWT.log("Main "+GWT.getModuleBaseURL());
RootPanel.get().add(clientImpls.getMainGUI());
}
MyGui:
public class MainGUI extends Composite
{
private TestGwt270ClientImpl serviceImpl;
private VerticalPanel vPanel;
private TextBox inputTB;
private Label outputLbl;
public MainGUI(TestGwt270ClientImpl serviceImpl)
{
this.vPanel = new VerticalPanel();
initWidget(vPanel);
this.inputTB = new TextBox();
this.inputTB.setText("Gib deinen Namen ein");
this.outputLbl = new Label("Hier kommt der output");
this.vPanel.add(this.inputTB);
this.vPanel.add(this.outputLbl);
Button sendBtn = new Button("send");
sendBtn.addClickHandler(new MyClickhandler());
this.vPanel.add(sendBtn);
}
public void updateOutputLbl(String output)
{
this.outputLbl.setText(output);
}
private class MyClickhandler implements ClickHandler
{
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
serviceImpl.sayHello(inputTB.getText());
}
}
}
Theservice:
@RemoteServiceRelativePath("testgwt270service")
public interface TestGwt270Service extends RemoteService
{
String sayHello(String name);
}
AsyncService:
public interface TestGwt270ServiceAsync
{
void sayHello(String name, AsyncCallback<String> callback);
}
ClientInterface:
public interface TestGwt270ServiceClientInt
{
void sayHello(String name);
}
Реализация Клиент:
public class TestGwt270ClientImpl implements TestGwt270ServiceClientInt
{
private TestGwt270ServiceAsync service;
private MainGUI maingui;
public TestGwt270ClientImpl(String url)
{
GWT.log(url);
// TODO Auto-generated constructor stub
this.service = GWT.create(TestGwt270Service.class);
ServiceDefTarget endpoint = (ServiceDefTarget) this.service;
endpoint.setServiceEntryPoint(url);
this.maingui = new MainGUI(this);
}
public MainGUI getMainGUI()
{
return this.maingui;
}
@Override
public void sayHello(String name) {
// TODO Auto-generated method stub
this.service.sayHello(name, new MyCallback());
}
private class MyCallback implements AsyncCallback<String>
{
@Override
public void onFailure(Throwable arg0) {
// TODO Auto-generated method stub
GWT.log("Failure");
maingui.updateOutputLbl("An Error has occured");
}
@Override
public void onSuccess(String arg0) {
// TODO Auto-generated method stub
GWT.log("Success");
maingui.updateOutputLbl(arg0);
}
}
}
ServerSideCode:
public class TestGwt270ServiceImpl extends RemoteServiceServlet implements TestGwt270Service
{
@Override
public String sayHello(String name) {
// TODO Auto-generated method stub
GWT.log("Hello " + name + "\nHier spricht der Server mit dir");
return "Hello " + name + "\nHier spricht der Server mit dir";
}
}
Моя проблема, когда я нажимаю кнопку, чтобы отправить свое имя на сервере я получаю следующее сообщение об ошибке:
HandlerManager.java:129 Uncaught com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) : Cannot read property 'sayHello_2_g$' of undefined
Я не знаю, откуда эта ошибка, и я надеюсь, что вы мне поможете.
OK, спасибо за редактирование :) в следующий раз, когда я сделаю это правильно – KilledByCheese