title: How to display data table in JSF page with database data
body: <p>I have a table in a database which is used for storing application configuration data.</p>
  
  <p>This is the table structure - it's very simple example:</p>
  
  <pre><code>SessionTTL             MaxActiveUsers         
  ---------------------- ---------------------- 
  30                     787                    
  </code></pre>
  
  <p>I want to display the table data in this way:</p>
  
  <pre><code>&lt;table border="1"&gt;
     &lt;tr&gt;
       &lt;td&gt;SessionTTL&lt;/td&gt;
       &lt;td&gt;30&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
       &lt;td&gt;MaxActiveUsers&lt;/td&gt;
       &lt;td&gt;787&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
       &lt;td&gt;option&lt;/td&gt;
       &lt;td&gt;value&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
       &lt;td&gt;option&lt;/td&gt;
       &lt;td&gt;value&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt; 
  </code></pre>
  
  <p>I tried to display the data using this JSF code and this Java code, but the result was not what I want:</p>
  
  <pre><code>              &lt;h:dataTable id="books"
                           columnClasses="list-column-center,
                           list-column-right, list-column-center,
                           list-column-right" headerClass="list-header"
                           rowClasses="list-row" styleClass="list-
                           background" value="#{DashboardController.getDashboardList()}" var="store"&gt;   
                  &lt;h:column&gt;
                        &lt;h:outputText  value="Session Timeout"/&gt;
                        &lt;h:outputText  value="Maximum Logged Users"/&gt;
                  &lt;/h:column&gt;
                  &lt;h:column&gt;                       
                        &lt;h:outputText value="#{store.sessionTTL} minutes"/&gt;
                        &lt;h:outputText value="#{store.maxActiveUsers}"/&gt;
                  &lt;/h:column&gt;
  
              &lt;/h:dataTable&gt; 
  
  
  
  
  public List&lt;Dashboard&gt; getDashboardList()throws SQLException{
  
          List&lt;Dashboard&gt; list = new ArrayList&lt;Dashboard&gt;();
  
          if(ds == null) {
                  throw new SQLException("Can't get data source");
          }
  
          Connection conn = ds.getConnection(); 
  
          if(conn == null) {
                  throw new SQLException("Can't get database connection");
          }
  
          PreparedStatement ps = conn.prepareStatement("SELECT * from GLOBALSETTINGS");
  
          try{
              //get data from database        
              ResultSet result = ps.executeQuery();
              while (result.next()){
                  Dashboard cust = new Dashboard();
                  cust.setSessionTTL(result.getString("SessionTTL"));
                  cust.setMaxActiveUsers(result.getString("MaxActiveUsers"));
                  list.add(cust);
              }
          }
          catch(Exception e1){
              // Log the exception.
          }
          finally{
              try{
                  ps.close();
                  conn.close();
              }
              catch(Exception e2){
                  // Log the exception.
              }
          }
          return list; 
      }
  </code></pre>
  
  <p>How I can display the data the way I want?</p>
  
  <p>Best wishes</p>