1

i'm a newbie here and in GWT. Well, i have some questions with CellTable... And i'm very upset with the problem. The problem is: When i make a setRowData or ListDataProvider.setList, all the data in the List i have repeats at all Columns. If i have 11 datas on the list, all 11 data repeats in 11 rows and all columns. To explain better, the image of issue.

http://imageshack.us/photo/my-images/713/celltable.jpg/

I don't know what i have to do to resolve this type of "problem". Anyway, i will post the code:

//TABLE CODE

    tablePesquisaResultados = new CellTable<String>();
    tablePesquisaResultados.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);
    tablePesquisaResultados.setTableLayoutFixed(true);
    tablePesquisaResultados.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
    flexTable.setWidget(2, 0, tablePesquisaResultados);

    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 10, true);
    pager.setDisplay(tablePesquisaResultados);

    tablePesquisaResultados.setWidth("1262px");

    colID = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colID, "ID");

    colNomeUsuario = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colNomeUsuario, "Nome do Usuário");

    colEmail = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colEmail, "Email");

    colCodigoUsuario = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colCodigoUsuario, "Código do Usuário");

    colTelefone = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colTelefone, "Telefone");

    colCodigoSituacao = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colCodigoSituacao, "Código da Situação");

    colDataAbertura = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colDataAbertura, "Data de Abertura");

    colDataEncerramento = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colDataEncerramento, "Data de Encerramento");

    colDescricao = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colDescricao, "Descrição do Chamado");

    colMidiaAnexada = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colMidiaAnexada, "Mídia Anexada");

    colStatusID = new TextColumn<String>() {
        @Override
        public String getValue(String object) {
            return object.toString();
        }
    };
    tablePesquisaResultados.addColumn(colStatusID, "Status ID");
    flexTable.getFlexCellFormatter().setColSpan(2, 0, 2);
    FlexTableHelper.fixRowSpan(flexTable);

//END TABLE CODE

//CODE TO INSERT DATA IN CELLTABLE

        ListDataProvider<String> dataProvider = new ListDataProvider<String>();     
    dataProvider.addDataDisplay(tablePesquisaResultados);
    dataProvider.setList(resultado);
    System.out.println(resultado);

//END CODE TO INSERT DATA IN CELLTABLE

Well, there is.

Thanks, in advice.

Katsutoshi
  • 45
  • 1
  • 4

1 Answers1

1

The problem is that for each column you use the same getValue function:

@Override
public String getValue(String object) {
   return object.toString();
}


You need specific functions for each column that return the value that you want to display in that column. For example for column colNomeUsuario:

colNomeUsuario = new TextColumn<String>() {
   @Override
   public String getValue(String object) {
      return object.getNomeUsuario();
   }
};


Edit

I just noticed the way you define your celltable:

tablePesquisaResultados = new CellTable<String>();


You need to define it like this:

tablePesquisaResultados = new CellTable<MyObject>();

Where MyObject is a class representing the information that you want to display in the celltable.

You can pass server objects to the client side using Request Factory, or GWT RPC.

Ioan Agopian
  • 788
  • 5
  • 9
  • Wow! This helps a lot. But.. another thing. how i will pass a Object with gets/sets to client-side? – Katsutoshi Nov 23 '11 at 21:58
  • Thank you for the help. I have to modify my entity class, because of the annotations, i can't serialize the object. DTO design is better than DAO in this case? – Katsutoshi Nov 24 '11 at 13:17
  • DAO is a good pattern because of the separation of concerns principle. The fact is that you may end up needing DTOs even when implementing DAO. That's one reason the GWT team added [RequestFactory](http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html). See this [post](http://stackoverflow.com/questions/7564568/gwt-rpc-dto-vs-dao). – Ioan Agopian Nov 24 '11 at 14:27
  • Hum. And the persistence? i can use JPA normally or i have to consider use Hibernate? – Katsutoshi Nov 24 '11 at 15:23
  • thanks a lot. I resolved my problem and a tons of others. Thank you so much – Katsutoshi Nov 24 '11 at 16:16
  • You're welcome. You should accept the answer if it helped solve your problem. – Ioan Agopian Nov 24 '11 at 17:42