How to add a dynamic content in tabular format using repeater in Wicket

1.3k views Asked by At

I am new to Wicket and am trying to add purely dynamic content in wicket. I have a list of object TableDataValuesVO which has a String tableName and a map columnNamesAndValues (containing columnName And its value). Each object in the list represent different data records of different table (the size of columnNameAndValues differ for each object). As of now I am using repeatingview for columnName and Value.but it displays one columnName per row and below that one columnValue per row.

Class to generate this component:
Html:

<table wicket:id="applicationDataView">

Java:

boolean columnNameRendered = false;
applicationDataView = new RepeatingView("applicationDataView")
RepeatingView tableView = new RepeatingView(applicationDataView.newChildId());
RepeatingView columnNameView = new RepeatingView(applicationDataView.newChildId());
tableView.add(new Label(applicationDataView.newChildId(),tableName));
applicationDataView.add(columnNameView);
applicationDataView.add(tableView);
List<dataVO> dataForTable= applicationDataByTable.get(tableName);
for (DataVO dataVO: dataForTable)
{
    RepeatingView columnValueView= new RepeatingView(applicationDataView.newChildId());
    if (!columnNameRendered)
    {
        for (String columnName : dataVO.getColumnNamesAndValues().keySet())
        {
            columnNameView.add(new Label(tableName+columnName,columnName));
        }
        columnNameRendered = true;
    }
    for (String columnName : dataVO.getColumnNamesAndValues().keySet())
    {
        String columnValue = tableDataValuesForRecordVO.getColumnNamesAndValues().get(columnName);
        columnValueView.add(new Label(applicationDataView.newChildId(),columnValue));
        applicationDataView.add(columnValueView);
    }
}

Actual result:

Table name1:
Column 1
Column 2
Column 3
Val11
Val12
....


Table name2:
    Column 1
    Column 2
    Column 3
    Column 4
    Val11
    Val12....

Expected Result:

Table Name1:

    Col1  col2  Col3
    val11 val12 val13
    val21 val22 val23


Table Name2:

        Co131  col32  Col33 col34
        val11 val12 val13  val14
        val21 val22 val23  val24

Please help in providing a solution to display the dynamic data?

1

There are 1 answers

0
Rob Audenaerde On BEST ANSWER

You can use, for example, a ListView that draws a lot of DataTables. (side note:I think this will be not very fast, as you will generate loads of HTML. )

Java:

List<DataVo> dataVoList = ... //create your list of datavo's

add(new ListView<DataVo>("listview", dataVoList) {
    protected void populateItem(ListItem<DataVo> item) {
        DataVo dataVo = (DataVo) item.getModelObject();
        final DataProvider dataProviderBasedOnVo = ... //create dataprovider here.         
        IColumn[] columns = ... //create columns here, based on the dataVo
        item.add(new DataTable("table", columns, dataProviderBasedOnVo, 10));
    }
});

HTML:

...
<div wicket:id="listview">
   <table wicket:id="table"></table>
</div>
...