I want to display a msg from server when user clicks a button on client web page. Here is my code. Can someone see it. It is running but fails when I input name & press button 'Press'.Displays msg 'check ur inputs'
here is stack trace:
[WARN] 404 - POST /lumiproj/testService (127.0.0.1) 1406 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Referer: http://127.0.0.1:8888/LumiProj.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 159
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/lumiproj/
X-GWT-Permutation: HostedMode
Content-Type: text/x-gwt-rpc; charset=UTF-8
Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1406
web.xml
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
LumiProjServiceImpl com.hello.server.LumiProjServiceImpl
LumiProjServiceImpl /lumiproj/greet
LumiProj.html
entrypoint class
package com.hello.client;
//import rpctest.client.RpctestService;
//import rpctest.client.RpctestServiceAsync;
import com.hello.shared.FieldVerifier;
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.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
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;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class LumiProj implements EntryPoint {
final TextBox nameText = new TextBox();
final Label nameLabel = new Label("Enter name");
final Button pressBtn = new Button("Press!");
final Button exitBtn = new Button("exit");
//final Label errorLabel = new Label();
private VerticalPanel mainpanel = new VerticalPanel();
private HorizontalPanel addpanel1 = new HorizontalPanel();
private HorizontalPanel addpanel2 = new HorizontalPanel();
private final LumiProjServiceAsync calNumbers = GWT
.create(LumiProjService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
addpanel1.add(nameLabel);
addpanel1.add(nameText);
addpanel2.add(pressBtn);
addpanel2.add(exitBtn);
mainpanel.add(addpanel1);
mainpanel.add(addpanel2);
pressBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String name = nameText.getValue();
calNumbers.calNumbers(name,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
Window.alert("check your inputs");
}
@Override
public void onSuccess(String result) {
// TODO Auto-generated method stub
Window.alert("answer="+result);
}
});}
});
// We can add style names to widgets
//sendButton.addStyleName("sendButton");
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
/*RootPanel.get("nameFieldContainer").add(nameField);
*
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);*/
RootPanel.get().add(mainpanel);
}
}
service interfaces:
package com.hello.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("testService")
public interface LumiProjService extends RemoteService {
String calNumbers(String name) throws IllegalArgumentException;
}
------------------
package com.hello.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface LumiProjServiceAsync {
void calNumbers(String name,
AsyncCallback<String> callback);
}
serviceIMPL
package com.hello.server;
import com.hello.client.LumiProjService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class LumiProServiceImpl extends RemoteServiceServlet implements LumiProjService {
@Override
public String calNumbers(String name) throws IllegalArgumentException {
String h = "Hello";
return h+" "+name;
}
}