Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

java - Create GWT CellTable Dynamically

I am stuck in a problem with GWT CellTable. I need to create celltable dynamically and I dont have entity (Bean) class to do so. I have seen all the examples of celltable and searched a lot to do so without entity class.

I need to populate table dynamically according to some metadata stored in database. I am able create table structure

Consider there are two classes one is GRID and another is COLUMN for the metadata and columns definition. GRID will have list of COLUMNS as a columns definition

    Class GRID {
List<COLUMN> columns;
}

Class COLUMN {
  String columnName;
}

Now i need to get grid from database and loop the columns to populate the cells (Columns) like :

com.google.gwt.user.cellview.client.Column<String, String> textColumn = new Column<String, String>(
                        new EditTextCell()) {
                    @Override
                    public String getValue(String object) {
                        return object;
                    }
                };

Now, I need to add some data to the celltable. but without entity there are no example how to populate the different columns. I have tried my self like : (Consider Grid have 3 columns)

List<String> data;

String a1 = "A1";
            String a2 = "A2";
            String a3 = "A3";

            data = new ArrayList<String>();
            data.add(a1);
            data.add(a2);
            data.add(a3);

final AsyncDataProvider<String> provider = new AsyncDataProvider<String>() {
            @Override
            protected void onRangeChanged(HasData<String> display) {
                updateRowData(0, data);
            }
          };
          provider.addDataDisplay(grid);
provider.updateRowCount(data.size(), true);

I am able to produce the output like :

A1 A1 A1

A2 A2 A2

A3 A3 A3

Actually output should be one row only like

A1 A2 A3

But failed to do so.

Please help.

Thankx,

Regards,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can represent your "rows" as List<String> instances, you have to change your parameterization from String to List<String> in your Grid, Column and data provider; and of course you have to call updateRowData with a List<List<String>>, not a List<String>.

You also need one Column instance per column, taking the value out of the List<String> by index:

class IndexedColumn extends Column<List<String>, String>
   private final int index;
   public IndexedColumn(int index) {
     super(new EditTextCell();
     this.index = index;
   }

   @Override
   public String getValue(List<String> object) {
      return object.get(this.index);
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...