title: Splitting up a List into smaller parts (with possible use of wicket)
body: <p>I've made an application that loads a query in from a property file, such as SELECT * FROM DATA. All this data is then loaded in each row at a time. The first time, we take the row which is id, name, phone, bday and division and put into a list called headlines. And then we put the data it self into a list called records. After that, we look past the headlines and just load our data continuesly into our records list. </p>
  
  <p>When we use wicket to show the data in a table for us, the outcome is this:
  <a href="http://i.imgur.com/d0Gsnr2.png" rel="nofollow">http://i.imgur.com/d0Gsnr2.png</a></p>
  
  <p>As you can see, it just prints out an entire row with all the data. We want the all the data to have seperate columns, according to the headlines. So it should be something similar to:</p>
  
  <p>ID - NAME - PHONE - BDAY - DIVISION</p>
  
  <p>123 - JOE - 10351053 - 20-12-2012 - EAST.</p>
  
  <p>How do we manage to do this? Our code is as follows:</p>
  
  <pre><code>public class DataHandlerImpl implements DataHandler {
  
  private final DataService dataService = new DataService();
  private final List&lt;Object&gt; records = new ArrayList&lt;&gt;();
  
  @Override
  public String getPropertyValue() {
      Properties prop = new Properties();
      String propFileName = "sqlQuery.properties";
  
      InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
      loadInputStreamCatchIOException(prop, inputStream);
      fileNotFoundException(inputStream, propFileName);
      String result = prop.getProperty("sqlQuery");
      return result;
  }
  
  @Override
  public Data getKeysAndValues() {
      String queryFromPropertyFile = getPropertyValue();
      List&lt;HashMap&lt;String, Object&gt;&gt; sqlQuery = dataService.getSqlQuery(queryFromPropertyFile);
      List&lt;String&gt; headlines = new ArrayList&lt;&gt;(sqlQuery.get(0).keySet());
      Collections.reverse(headlines);
  
      createListOfRecords(sqlQuery, headlines);
  
      return new DataImpl(headlines, records);
  }
  
  @Override
  public int numberOfRecords() {
      return getKeysAndValues().getRecords().size();
  }
  
  private void loadInputStreamCatchIOException(Properties prop, InputStream inputStream) {
      try {
          prop.load(inputStream);
      } catch (IOException ex) {
          Logger.getLogger(DataHandlerImpl.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  
  private void fileNotFoundException(InputStream inputStream, String propFileName) {
      if (inputStream == null) {
          try {
              throw new FileNotFoundException("property file '" + propFileName + "
  ' not found in    the classpath");
          } catch (FileNotFoundException ex) {
              Logger.getLogger(DataHandlerImpl.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  }
  
  private void createListOfRecords(List&lt;HashMap&lt;String, Object&gt;&gt;
  sqlQuery, List&lt;String&gt; headlines)        {
      for (HashMap&lt;String, Object&gt; values : sqlQuery) {
          List&lt;Object&gt; newRow = new ArrayList&lt;&gt;();
          for (String record : headlines) {
              newRow.add(values.get(record));
          }
          records.add(newRow);
      }
  }
  }
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>public class SimpleDataView extends SimpleDataViewPage {
  
  IModel ldm;
  
  public SimpleDataView() {
      ldm = new LoadableDetachableModel&lt;Data&gt;() {
  
          @Override
          protected Data load() {
              DataHandlerImpl dataHandler = new DataHandlerImpl();
              return dataHandler.getKeysAndValues();
          }
      };
      add(new Label("size", "Number of records: " + getData().getRecords().size()));
  
      add(new Label("headlines", new Model&lt;String&gt;() {
  
          @Override
          public String getObject() {
              return getData().getHeaders().toString();
          }
  
      }));
  
      add(new Label("records", new Model&lt;String&gt;() {
  
          @Override
          public String getObject() {
              return getData().getRecords().toString();
          }
  
      }));
  }
  }
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:wicket="http://wicket.apache.org"&gt;
  
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;Data presentation&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h3&gt;Data&lt;/h3&gt;
      &lt;h4 wicket:id="size"&gt;&lt;/h4&gt;
      &lt;table border="1"&gt;
          &lt;tbody&gt;
          &lt;thead&gt;
          &lt;td&gt;&lt;a wicket:id="headlines" href="#"&gt;NAME&lt;/a&gt;&lt;/td&gt;
  &lt;/thead&gt;
           &lt;td wicket:id="records"&gt;
      &lt;/td&gt;
      &lt;/tbody&gt;
  
  
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If any further information is needed, please don't hesitate to ask.</p>