问题描述
- GWT中写了textBox不能获得值
-
下面是方法:package com.packtpub.gwtbook.samples.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.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.RootPanel; import com.google.gwt.user.client.ui.TextBox; public class Samples implements EntryPoint { public void onModuleLoad() { //创建textbox final TextBox primeNumber = new TextBox(); System.out.println("得到值==="+primeNumber.getText()); final PrimesServiceAsync primesService = (PrimesServiceAsync) GWT .create(PrimesService.class); ServiceDefTarget endpoint = (ServiceDefTarget) primesService; endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "primes"); //创建button final Button checkPrim = new Button(); RootPanel.get().add(primeNumber); RootPanel.get().add(checkPrim); checkPrim.setText("点一次"); //点击调动事件 checkPrim.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // TODO Auto-generated method stub AsyncCallback callBack = new AsyncCallback() { public void onFailure(Throwable caught) { // TODO Auto-generated method stub Window.alert("服务出现错误"); } public void onSuccess(Object result) { // TODO Auto-generated method stub if (((Boolean) result).booleanValue()) { Window.alert("yes," + primeNumber.getText() + "是素数!"); } else { Window.alert("no," + primeNumber.getText() + "不是素数!"); } } }; //方法判断获得值是否为素数,返回值为boolean primesService.isPrimeNumber(Integer.parseInt(primeNumber.getText()),callBack); } }); } }
Async中一个接口:
public interface PrimesServiceAsync { public void isPrimeNumber(int numberToVerify,AsyncCallback callback); }
不知为什么primeNumber.getText()为什么总是为空?
GWT development mode中运行报错。
解决方案
http://www.cnblogs.com/zping/archive/2009/07/15/1524243.html
时间: 2024-12-31 02:26:46