View Full Version : Rendering nested models on a grid

2 Aug 2009, 3:06 AM

I needed some help in rendering nested models on a grid.I have a User model and an Contact model.(One -to -Many relationship). So on my grid i wanted to render the different contacts phones for a user.
Something Like

User1 Contact1 Phone Contact2 Phone
User2 Contact1 Phone Contact2 Phone Contact3 Phone

My Grid doesnot support Model Processor , so how should i achieve this

private class Contact extends BaseModel {
private String phone;
public Contact(String phone) {
this.phone = phone;
public String getPhone() {
return phone;
public void setPhone(String phone) {
this.phone = phone;
private class User extends BaseModel {
private Contact contact;
private String name;
public User(String name, Contact contact) {
this.name = name;
this.contact = contact;
public Contact getContact() {
return contact;
public String getName() {
return name;
public void setContact(Contact contact) {
this.contact = contact;
public void setName(String name) {
this.name = name;

in case of a list view i could have done something like this, but this is not supported for a grid.How should i accomplish this for a grid control.

FormPanel panel = new FormPanel();
final DualListField<User> lists = new DualListField<User>();
ListStore<User> store = new ListStore<User>();
store.setStoreSorter(new StoreSorter<User>());
store.add(new User("ram", new Contact("55-878-098")));
store.add(new User("ramesh", new Contact("105-878-098")));
store.add(new User("azhar", new Contact("95-878-098")));
store.add(new User("vivek", new Contact("57-878-098")));
store.add(new User("george", new Contact("48-878-098")));

ListField<User> from = lists.getFromList();
from.getListView().setModelProcessor(new ModelProcessor<User>() {
public User prepareData(User model) {
if (model != null) {
model.set("MyDisplayName", model.getName() + model.getContact().getPhone());
return model;

6 Aug 2009, 4:30 AM
maybe treegrid is interesting for you?


1. try: create a new store

otherwise i would try to create a store with columns as needed and populate the data to this store with "<X extends BaseModel>".set(propertyname, value)

2. try
ModelProcessor is not availabel

3. try
but you can use a column renderer. you create this additional columns and add there your columnrenderer which gets the data from the datastore.

there is a similar question here:
ModelProcessor in GridView