我在用於存儲應用程序配置數據的數據庫中有一個表。如何使用數據庫數據在JSF頁面中顯示數據表
這是表結構 - 這是非常簡單的例子:
SessionTTL MaxActiveUsers
---------------------- ----------------------
30 787
我想用這種方式來顯示錶中的數據:
<table border="1">
<tr>
<td>SessionTTL</td>
<td>30</td>
</tr>
<tr>
<td>MaxActiveUsers</td>
<td>787</td>
</tr>
<tr>
<td>option</td>
<td>value</td>
</tr>
<tr>
<td>option</td>
<td>value</td>
</tr>
</table>
我嘗試使用這個JSF代碼來顯示數據和這個Java代碼,但結果不是我想要的:
<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">
<h:column>
<h:outputText value="Session Timeout"/>
<h:outputText value="Maximum Logged Users"/>
</h:column>
<h:column>
<h:outputText value="#{store.sessionTTL} minutes"/>
<h:outputText value="#{store.maxActiveUsers}"/>
</h:column>
</h:dataTable>
public List<Dashboard> getDashboardList()throws SQLException{
List<Dashboard> list = new ArrayList<Dashboard>();
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;
}
我如何顯示數據是我想要的方式?
最良好的祝願
歡迎來到Stack Overflow!這是一個乾淨的問答網站,每個人都可以在協議/不同意的情況下投票。這不是一個老式的論壇,每個人都會在協議/不同意的情況下以混亂的形式重複彼此,就像你試圖做的那樣。我建議不要在已經回答的問題上發佈答案,除非你確實需要添加大量的東西 - 在這種情況下似乎不是這種情況。只需通過發佈良好答案首先獲得15個代表,然後您可以在協議上投票表決其他人的帖子,而不是重複他們。 – BalusC 2013-04-16 12:18:52