0

I have a json of below format -

{"name":"abc","id":"101","age":"22"}

I want to display this json in Bootsfaces Table with key as one column and values as other column.

My approach is to convert this json to List (Keys in one list and Values in another list)and then pass to 2 different columns in Table.

ListOfKeys - [name , id , age]

ListOfValues - [abc , 101 , 22]

But I am not finding any easy approach to display these lists to Table in separate columns.

Can anyone please suggest programmatically..how to convert List to Bootsfaces Table

or any other easy approach for converting json to Table?

I am just a beginner.Any help would be appreciated.Thankyou.

Spandana
  • 121
  • 1
  • 2
  • 13
  • I suggest you to convert your JSON to POJO first..Are you doing that?? – Akshay Feb 09 '17 at 06:11
  • No.. But Can you please explain programmatically how to do that? – Spandana Feb 09 '17 at 06:16
  • I doubt converting the Json to a POJO makes things simpler :). Quite the contrary. You'd need the reflection API to iterate the variables of the POJO. If the question is to create a table consisting of a "keys" and "values" column, that is. – Stephan Rauh Feb 09 '17 at 22:43

1 Answers1

0

Create an object containing both key and value:

public class Row {
  private String key;
  private String value;
  // plus getters and setters (omitted for brevity)
}

and pass an array of these objects to the datatable:

public class MyBean {
  private List<Row> table = new ArrayList<>();
  // plus getter and setter
  public MyBean(String json) {
    // parse Json and populate the table array with it
    // (omitted for brevity)
  }
}


<b:dataTable value="#{myBean.table}" var="row">
  <b:dataTableColumn value="#{row.key}" />
  <b:dataTableColumn value="#{row.value}" />
</b:dataTable>
Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37