abaig
25 Nov 2008, 8:26 AM
Hi
I am trying to create a ComboBox with data read through Toplink. I am using a GWT RPC service to create proxy for Toplink class and query database.
I am able to successfully retrieve data from Toplink. But I can't see the countries when combox box is expanded. At the same time, when I type in partial country name, I can see combo box filling in rest of the name. This means data is added to combobox but not rendered property. Also, the trigger icon in combobox is not in line with the text field. I guess I am missing something basic but unable to figure it out. Any help would be really appreciated.
Thanks,
Amjad.
Here is the sample code:
UserRemoteService contains RPC proxy for toplink objects.
Country is dataholder for country data and it extends BaseModelData.
public class UserRPC implements EntryPoint {
private ComboBox<Country> cWidget = new ComboBox<Country>();
private final UserRemoteServiceAsync uService = getUserService();
public void onModuleLoad() {
System.out.println("UserRPC: onModuleLoad");
HorizontalPanel fPanel = new HorizontalPanel();
cWidget.setEmptyText("Select a state...");
cWidget.setDisplayField("name");
cWidget.setBorders(true);
cWidget.setWidth(200);
cWidget.setTypeAhead(true);
cWidget.setTriggerAction(TriggerAction.ALL);
cWidget.setAllowBlank(true);
cWidget.setAutoHeight(true);
//Needed to fill in some dummy value as otherwise I got Assert null error
fillEmptyCombo();
fillCountryCombos();
fPanel.add(cWidget);
RootPanel.get().add(fPanel);
}
private UserRemoteServiceAsync getUserService() {
UserRemoteServiceAsync userService = (UserRemoteServiceAsync) GWT.create(UserRemoteService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) userService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "user";
endpoint.setServiceEntryPoint(moduleRelativeURL);
return userService;
}
private void fillEmptyCombo() {
Country country = new Country();
country.setName(" ");
ListStore<Country> countries= new ListStore<Country>();
countries.add(country);
cWidget.setStore(countries);
}
private void fillCountryCombos() {
ListStore<Country> countries = new ListStore<Country>();
if(uService != null) {
uService.getCountries(new AsyncCallback<List<Country>>() {
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
public void onSuccess(List<Country> result) {
// TODO Auto-generated method stub
ListStore<Country> countries = new ListStore<Country>();
Iterator<Country> iter = result.iterator();
while(iter.hasNext()) {
Country country = iter.next();
country.set("name", country.getName());
country.set("iso", country.getIso());
countries.add(country);
}
cWidget.setStore(countries);
}
});
}
}
}
I am trying to create a ComboBox with data read through Toplink. I am using a GWT RPC service to create proxy for Toplink class and query database.
I am able to successfully retrieve data from Toplink. But I can't see the countries when combox box is expanded. At the same time, when I type in partial country name, I can see combo box filling in rest of the name. This means data is added to combobox but not rendered property. Also, the trigger icon in combobox is not in line with the text field. I guess I am missing something basic but unable to figure it out. Any help would be really appreciated.
Thanks,
Amjad.
Here is the sample code:
UserRemoteService contains RPC proxy for toplink objects.
Country is dataholder for country data and it extends BaseModelData.
public class UserRPC implements EntryPoint {
private ComboBox<Country> cWidget = new ComboBox<Country>();
private final UserRemoteServiceAsync uService = getUserService();
public void onModuleLoad() {
System.out.println("UserRPC: onModuleLoad");
HorizontalPanel fPanel = new HorizontalPanel();
cWidget.setEmptyText("Select a state...");
cWidget.setDisplayField("name");
cWidget.setBorders(true);
cWidget.setWidth(200);
cWidget.setTypeAhead(true);
cWidget.setTriggerAction(TriggerAction.ALL);
cWidget.setAllowBlank(true);
cWidget.setAutoHeight(true);
//Needed to fill in some dummy value as otherwise I got Assert null error
fillEmptyCombo();
fillCountryCombos();
fPanel.add(cWidget);
RootPanel.get().add(fPanel);
}
private UserRemoteServiceAsync getUserService() {
UserRemoteServiceAsync userService = (UserRemoteServiceAsync) GWT.create(UserRemoteService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) userService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "user";
endpoint.setServiceEntryPoint(moduleRelativeURL);
return userService;
}
private void fillEmptyCombo() {
Country country = new Country();
country.setName(" ");
ListStore<Country> countries= new ListStore<Country>();
countries.add(country);
cWidget.setStore(countries);
}
private void fillCountryCombos() {
ListStore<Country> countries = new ListStore<Country>();
if(uService != null) {
uService.getCountries(new AsyncCallback<List<Country>>() {
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
public void onSuccess(List<Country> result) {
// TODO Auto-generated method stub
ListStore<Country> countries = new ListStore<Country>();
Iterator<Country> iter = result.iterator();
while(iter.hasNext()) {
Country country = iter.next();
country.set("name", country.getName());
country.set("iso", country.getIso());
countries.add(country);
}
cWidget.setStore(countries);
}
});
}
}
}