1
我使用託管的bean將數據從jsf頁面插入數據庫。
但問題是,當我的jsf頁面加載時,現有的bean值顯示在表單域中,但我想在加載時顯示錶單域爲空。 請回復。 在此先感謝。如何用空字段重新顯示錶單?
以下是我的代碼片段 Bean類:
public class Employee implements Serializable{
private int eId;
private String name;
public String addEmployee(){
try{
//dbconnection
String query = "insert into emp values(?,?)";
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt = conn.prepareStatement(query); // create a statement
pstmt.setInt(1,this.eId);
pstmt.setString(2,this.eName);
return "success-page";
}catch(Exception e){
return "failure-page";
}
}
JSF頁面: -
<html>
<body>
<h:form>
Id
<h:inputText value="#{employee.eId}">
<f:convertNumber/>
</h:inputText>
Name
<h:inputText value="#{employee.eName}">
<f:validateRegex pattern="[a-zA-Z ]*"/>
</h:inputText>
</h:form>
</body>
</html>