我無法使用h:dataTable獲取表值。h:dataTable實現中的問題
請回復?
Bean類: -
public class Employee implements Serializable{
private int eId;
private String eName;
private ResultSet viewEmployee;
public Connection getVConnection() throws Exception{
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:globldb3";
String username = "scott";
String password = "tiger";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public ResultSet getViewEmployee() throws Exception{
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getVConnection();
String query = "select * from employee where e_id>?";
pstmt = conn.prepareStatement(query); // create a statement
pstmt.setInt(1,this.eId); // set input parameter
result = pstmt.executeQuery();
return result;
}finally {
try {
result.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public String v2(){
try{
getViewEmployee();
return "view-employee-p.xhtml";
}catch(Exception e){
e.printStackTrace();
return "home.xhtml";
}
}
JSF頁面1: -
<h:panelGrid columns="3" cellpadding="2" border="2" styleClass="panelGridColums"> Id
<h:inputText id="id" label=" " value="#{employee.eId}"
required="true" requiredMessage="Field cannot be left blank"
converterMessage="Not a valid id, id must be betwenn 1 and 9999." maxlength="4">
<f:convertNumber/>
</h:inputText>
<h:message for="id" styleClass="errorMessages" showDetail="false" showSummary="true"/>
</h:panelGrid>
<h:commandButton value="View" action="view-page.xhtml"/>
視圖page.xhtml:
<h:dataTable value="#{employee.viewEmployee}" var="e">
<h:column>
<f:facet name="header">Employee id</f:facet>
#{e.E_ID};
</h:column>
<h:column>
<f:facet name="header">Employee id</f:facet>
#{e.E_Name};
</h:column>
</h:dataTable>
在此先感謝。
你可以停止在標題中放置「一個非常小的問題」或類似的東西嗎?它並沒有給出一見到具體問題的清晰畫面。我已經將它們編輯了幾次。請自己拿出一個明確的標題,用一句話總結具體問題,然後點擊「編輯」鏈接。 – BalusC 2011-05-09 00:57:05
@BalusC:好的,謝謝你的建議。 – Adnan 2011-05-09 01:05:02