Datatable showing too much values

Hi,

I've got a page that should display all records from a database in a datatable dynamically. The code that I have right now works fine if the database table contains only 1 record.

If it contains 2 records, each <td> will contain the info of the first and the second record.

If it contains 3 records each <td> will contain the info of the first, second and third record

And so on...

For example:

If the database table looks as follows:

id fullname mail

-

id1 Test1 t1@test.com

id2 Test2 t2@test.com

The output currently looks like this:

|id |fullname |mail

|id1 id2|Test1 Test2|t1@test.com t2@test.com

|id1 id2|Test1 Test2|t1@test.com t2@test.com

And it should look like this:

|id |fullname |mail

|id1 |Test1 |t1@test.com

|id2 |Test2 |t2@test.com

This is the method that is used to fill the datatable:

public String dataTableAction(){

ResultSet rs = this.readORAData("SELECT * FROM MyTable");

// The method readORAdata returns the correct resultSet

this.dataTable1.setBorder(5);

this.dataTable1.setCellpadding("1");

this.dataTable1.setVar("viewall");

HtmlOutputText headerComponent =new HtmlOutputText();

headerComponent.setValue("Id");

column1.setHeader(headerComponent);

headerComponent =new HtmlOutputText();

headerComponent.setValue("FullName");

column2.setHeader(headerComponent);

headerComponent =new HtmlOutputText();

headerComponent.setValue("Mail");

column3.setHeader(headerComponent);

headerComponent =new HtmlOutputText();

headerComponent.setValue("Startdate");

column4.setHeader(headerComponent);

headerComponent =new HtmlOutputText();

headerComponent.setValue("Enddate");

column5.setHeader(headerComponent);

try{

while(rs.next()){

this.setId(rs.getString("fl_id"));

this.setFullName(rs.getString("fl_fullname"));

this.setMail(rs.getString("fl_mail"));

this.setStartdate(rs.getString("fl_startdate"));

this.setEnddate(rs.getString("fl_enddate"));

HtmlOutputText column1Text=new HtmlOutputText();

column1Text.setValue(rs.getString("fl_id"));

column1.getChildren().add(column1Text);

HtmlOutputText column2Text=new HtmlOutputText();

column2Text.setValue(rs.getString("fl_fullname"));

column2.getChildren().add(column2Text);

HtmlOutputText column3Text=new HtmlOutputText();

column3Text.setValue(rs.getString("fl_mail"));

column3.getChildren().add(column3Text);

HtmlOutputText column4Text=new HtmlOutputText();

column4Text.setValue(rs.getString("fl_startdate"));

column4.getChildren().add(column4Text);

HtmlOutputText column5Text=new HtmlOutputText();

column5Text.setValue(rs.getString("fl_enddate"));

column5.getChildren().add(column5Text);

}

ResultSetDataModel dataModel=new ResultSetDataModel();

dataModel.setWrappedData(rs);

dataTable1.setValue(dataModel);

}

catch(SQLException e){

System.out.println(e.getMessage() +"at Viewall.dataTableAction");

}

returnnull;

}

Has anybody got an idea of what I'm doing wrong here?

[4580 byte] By [Wouter9a] at [2007-11-26 14:50:26]
# 1
You'd better to use a panelGrid for static data which is added manually row by row. The h:dataTable is intented to be used for dynamic data based on an iterated model.If you really want to use a datatable, check here how to use it: http://balusc.xs4all.nl/srv/dev-jep-dat.html
BalusCa at 2007-7-8 8:38:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...