Window.alert(caught.toString());
ContactUs
当我在我的 gwt 应用程序中使用 rpc 时,in 会提醒这个异常。谁能告诉我为什么会这样?
Java类如下:-
ContactUs.java :-
package com.businesstool.home.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
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.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.event.logical.shared.AttachEvent;
public class ContactUs extends Composite implements HasText {
private static ContactUsUiBinder uiBinder = GWT
.create(ContactUsUiBinder.class);
@UiField TextBox fullName;
@UiField TextBox emailId;
@UiField TextBox subject;
@UiField TextArea message;
@UiField Button postUs;
@UiField Hyperlink home;
interface ContactUsUiBinder extends UiBinder<Widget, ContactUs> {
}
public ContactUs() {
initWidget(uiBinder.createAndBindUi(this));
}
@Override
public String getText() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setText(String text) {
// TODO Auto-generated method stub
}
@UiHandler("postUs")
void onPostUsClick(ClickEvent event) {
ContactUsBean contactUsBean=new ContactUsBean();
contactUsBean.setFullName(fullName.getText());
contactUsBean.setEmail(emailId.getText());
contactUsBean.setSubject(subject.getText());
contactUsBean.setMessage(message.getText());
if(contactUsBean.getFullName()==null || contactUsBean.getFullName().isEmpty()) {
Window.alert("Please fill First Name/Company Name");
} else if(contactUsBean.getEmail()==null || contactUsBean.getEmail().isEmpty()) {
Window.alert("Please fill contact email");
} else if(contactUsBean.getSubject()==null || contactUsBean.getSubject().isEmpty()) {
Window.alert("Please fill a subject");
} else if(contactUsBean.getMessage()==null || contactUsBean.getMessage().isEmpty()) {
Window.alert("Please fill your message");
} else {
ContactUsSubmissionServiceAsync contactUsSubmissionServiceAsync=ContactUsSubmissionService.Util.getInstance();
AsyncCallback<String> asyncCallback=new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
Window.alert(result);
fullName.setText("");
emailId.setText("");
subject.setText("");
message.setText("");
}
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.toString());
}
};
ServiceDefTarget serviceDefTarget=(ServiceDefTarget) contactUsSubmissionServiceAsync;
String moduleRelativeURL=GWT.getModuleBaseURL()+"ContactUsSubmissionService";
serviceDefTarget.setServiceEntryPoint(moduleRelativeURL);
// contactUsSubmissionServiceAsync.submitContactUs(fName, email, subj, msg, asyncCallback);
contactUsSubmissionServiceAsync.submitContactUs(contactUsBean, asyncCallback);
}
}
@UiHandler("home")
void onHomeAttachOrDetach(AttachEvent event) {
}
@UiHandler("home")
void onHomeClick(ClickEvent event) {
RootPanel rootPanel=RootPanel.get();
rootPanel.remove(0);
rootPanel.add(new IndexPage());
}
}
ContactUsSubmissionService.java :-
package com.businesstool.home.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("ContactUsSubmissionService")
public interface ContactUsSubmissionService extends RemoteService {
/**
* Utility class for simplifying access to the instance of async service.
*/
public static class Util {
private static ContactUsSubmissionServiceAsync instance;
public static ContactUsSubmissionServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(ContactUsSubmissionService.class);
}
return instance;
}
}
public abstract String submitContactUs(ContactUsBean contactUsBean);
}
ContactUsSubmissionServiceAsync.java :-
package com.businesstool.home.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface ContactUsSubmissionServiceAsync {
public abstract void submitContactUs(ContactUsBean contactUsBean,
AsyncCallback<String> callback);
}
ContactUsSubmissionServiceImpl.java :-
package com.businesstool.home.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import vsrd.web.mail.SendMail;
import vsrd.web.mail.Validator;
import com.businesstool.home.client.ContactUsBean;
import com.businesstool.home.client.ContactUsSubmissionService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class ContactUsSubmissionServiceImpl extends RemoteServiceServlet
implements ContactUsSubmissionService {
/**
*
*/
private static final long serialVersionUID = -6319962734395453042L;
@Override
public void service(final HttpServletRequest request,
HttpServletResponse response) {
}
@Override
public String submitContactUs(ContactUsBean contactUsBean) {
String fullName = contactUsBean.getFullName();
String email = contactUsBean.getEmail();
String subject = contactUsBean.getSubject();
String message = contactUsBean.getMessage();
String output = "Successfully sent your message to the admistrator.\nThanks";
Validator validator = new Validator();
if (fullName == null || fullName.trim().isEmpty()) {
output = "Invalid full name, failed posting message";
} else if (email == null || email.trim().isEmpty()) {
output = "Invalid Email Id, failed posting message";
} else if (subject == null || subject.trim().isEmpty()) {
output = "Invalid subject, failed posting message";
} else if (message == null || message.trim().isEmpty()) {
output = "Invalid message, failed posting message";
} else if (!validator.isValidEmail(email)) {
output = "Invalid email id, failed posting message";
} else {
message += "\n" + "Full name : " + fullName + "\nEMail Id : "
+ email;
SendMail sendMail = new SendMail();
String mailStatus = sendMail.sendMail("visruthcv@gmail.com",
"xxx@gmail.com", "Mr.XXX", email, subject,
message);
if (mailStatus == null) {
String mailStatus2 = sendMail
.sendMail(
"xxx@gmail.com",
email,
fullName,
"xxx@gmail.com",
"Confirmation mail from http://xxx.appspot.com",
"Thank you for your valuable message\n\n\nThanks & Regards\nAdministrator");
if (mailStatus2 == null) {
output += ", we have sent a confirmation message to your email.";
} else {
output += ",\n we have received your mail \nbut we failed to send a confirmation mail to "
+ email + " \nplease give the correct email id.";
}
} else {
output = "Posting failed";
}
}
return output;
}
}
ContactUsBean.java :-
package com.businesstool.home.client;
import java.io.Serializable;
public class ContactUsBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2345125743115814903L;
private String fullName;
private String email;
private String subject;
private String message;
//getter setter methods.....
}