下列代码实现的是 一个下拉列表的功能:
?
package com.tservice.pga.smapp.client.meeting;import com.google.gwt.core.client.gwt;import com.google.gwt.user.client.rpc.asynccallback;import com.google.gwt.user.client.rpc.servicedeftarget;import com.smartgwt.client.data.fields.datasourceenumfield;import com.smartgwt.client.data.fields.datasourcetextfield;import com.smartgwt.client.widgets.form.fields.selectitem;import com.tservice.pga.smapp.client.service.smservice;import com.tservice.pga.smapp.client.service.smserviceasync;public class publicuserstringarraylist { smserviceasync mainservice = (smserviceasync) gwt.create(smservice.class); servicedeftarget endpoint = (servicedeftarget) mainservice; string modulebaseurl = gwt.getmodulebaseurl()+"rpc"; datasourcetextfield peopletext=null; selectitem select=null; public publicuserstringarraylist(string titleid,string name){ endpoint.setserviceentrypoint(modulebaseurl); //"people","参与者" peopletext=new datasourcetextfield(titleid,name,10); select=new selectitem(titleid,name); mainservice.getuserlists(new asynccallback(){ public void onfailure(throwable caught) { } public void onsuccess(object result) { string[] str=(string[])result; select.setvaluemap(str); } }); }}
??
其他前端页面调用:
?
final publicuserstringarraylist userlist=new publicuserstringarraylist("people","参与者");
?
dynamicform form=new dynamicform(); form.setusealldatasourcefields(true);//只有这样才能让datasource控件与常规控件(selectitem)同事显示 form.setdatasource(datasource); form.setfields(userlist.select);
?
datasource datasource=new datasource();datasource.setclientonly(true);
?参考:
http://dragon0929.iteye.com/blog/611864#comments
?
?