PDA

View Full Version : My Combobox problem



hraing
28 Mar 2011, 6:46 AM
I´m trying to user a loader to put data into my combobox, My project follows mvp.

I tried to follow this example but I´m using a database in stead of the proxy so I´m trying to reconfigure it.

http://www.sencha.com/examples/explorer.html#advancedcombobox

The problem is when I start searching I only get the loading signal and I can´t find any of my contacts



package is.mappan.client.widget;

import is.mappan.shared.model.Contact;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoader;
import com.extjs.gxt.ui.client.data.PagingModelMemoryProxy;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;


/**
* @author Hrafn Ingvarsson
*
*/
public class UsersComboBox{

PagingLoader<PagingLoadResult<Contact>> loader;
ListStore<Contact> usersListStore;
List<Contact> userList;
ComboBox<Contact> usersComboBox;


/**
* The Constructor
*/
public UsersComboBox() {
loader = new BasePagingLoader<PagingLoadResult<Contact>>(null);
usersListStore = new ListStore<Contact>(loader);
userList = new ArrayList<Contact>();
usersComboBox = new ComboBox<Contact>();
usersComboBox.setStore(usersListStore);
usersComboBox.setWidth(400);
usersComboBox.setDisplayField("name");
usersComboBox.setItemSelector("div.search-item");
usersComboBox.setTemplate(getTemplate());
usersComboBox.setTitle("Veldu tengilið til að skrá");
usersComboBox.setEmptyText("Skráðu Tengilið...");
usersComboBox.setFieldLabel("Tengiliðir");
usersComboBox.setHideTrigger(true);
usersComboBox.setPageSize(10);


}

/**
* Refresh the loader when user opens the form with the combobox
*/
public void refreshUsers()
{
loader = new BasePagingLoader<PagingLoadResult<Contact>>(searchUsers());

usersListStore = new ListStore<Contact>(loader);
loader.load();
}

/**
* @return This Function will filter my combobox when it´s finished
*/
public PagingModelMemoryProxy searchUsers()
{
List<Contact> tmpList = new ArrayList<Contact>();

for(int i = 0; i < userList.size(); i++)
{
tmpList.add(userList.get(i));
}

return new PagingModelMemoryProxy(tmpList);
}

/**
* @param users A list of users
*
*/
public void setUsers(List<Contact> users) {

this.userList.clear();
this.userList.addAll(users);

//Then I refresh the combobox.
refreshUsers();
}

private native String getTemplate() /*-{
return [
'<tpl for="."><div class="search-item">',
'<h3><span>Nafn: {name}</h3>, Heimilisfang: {address}</span>',
'</div></tpl>'
].join("");
}-*/;

/**
* @return ComboBox with the Mappan users
*/
public ComboBox<Contact> getUsers() {
return usersComboBox;
}
}