PDA

View Full Version : Combobox setDisplayField is set but doesn't show text, only empty lines.



ronaldmathies
30 Jun 2009, 11:05 AM
I'm having a small problem is that my combobox displays that there are rows but it doesn't show the text within the rows (so i have empty rows).

My code is as follow:

// Create a ListLoader
BaseListLoader<ListLoadResult<ProjectModelData>> projectListLoader =
new BaseListLoader<ListLoadResult<ProjectModelData>>(new ProjectRpcProxy());

// Force loading of the data
projectListLoader.load();

ComboBox<ProjectModelData> projectCombobox = new ComboBox<ProjectModelData>();
projectCombobox.setEmptyText("Select...");
projectCombobox.setDisplayField("description");
projectCombobox.setForceSelection(true);
projectCombobox.setStore(new ListStore<ProjectModelData>(projectListLoader));

The ProjectRpcProxy retrieves the data from the server and this works find, the store has the data after retrieving it form the server.

The ProjectModelData is as follow:

public class ProjectModelData extends BaseModelData {

private static final long serialVersionUID = 1L;

private CProject project = null;

public ProjectModelData(CProject project) {
this.project = project;
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Object get(String property) {
if (property.equals("description")) {
return project.getDescription();
} else if (property.equals("history")) {
return project.isHistory();
}

return null;
}

/**
* Returns the project.
* @return the project.
*/
public CProject getProject() {
return this.project;
}

}

I have used this ProjectModelData already in a number of screens for grids and their it works fine.

When i now open the list i get this list with empty lines, if i select a value and see what is selected i can see it selected the correct value.

if i debug i can see that it retrieves the data from the model that needs to be displayed.

However, why doesn't iut actually show the data in the combo box.

Does anybody have a clue how to solve this?

ejmenendez
2 Mar 2010, 5:08 AM
any news on that? I know it's from a while back but I have the same problem using RPC to get datamodels from a database and add them to a combo. The text is not showing but if I select one option it shows and returns the expected value. I don't know how to solve it and it seems that nobody else does.
Thanks

sven
2 Mar 2010, 5:10 AM
The BaseModelData that is used is incorrect. The values needs to be written to the map and not to private members.

ronaldmathies
2 Mar 2010, 5:24 AM
It's been quite some time but if i understand your reply, i now have that CProject object in my base model which contains the data for the model which is wrong, i should use the map from the super to store the data right? (i have no need for the sollution anymore but just to clarify it for myself)

ejmenendez
2 Mar 2010, 5:28 AM
Sven, you're right, haven't seen that that code misses calling set() on BaseModelData, in my model it does but still I get blank dropdown - posted about it already.

ejmenendez
2 Mar 2010, 5:38 AM
RonaldMathies: yes, you should use the set(key,value) method to add the values to the BaseModelData instead of setting private attributes.
See you