Jsf 如何重新显示具有空字段的表单?
我正在使用托管bean将数据从jsf页面插入数据库。Jsf 如何重新显示具有空字段的表单?,jsf,jsf-2,javabeans,Jsf,Jsf 2,Javabeans,我正在使用托管bean将数据从jsf页面插入数据库。 但问题是,当加载jsf页面时,表单字段中会显示现有的bean值,但我希望在加载时将表单字段显示为空。 请回复。 提前谢谢 下面是我的代码片段 Bean类: public class Employee implements Serializable{ private int eId; private String name; public String addEmployee(){ try{ //dbconnection String quer
但问题是,当加载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>
身份证件
名称
将bean放入请求或视图范围(因此不放入会话范围)。这样,当请求一个新视图时,bean将被丢弃并重新创建
此外,还需要指示webbrowser不要缓存页面。当从浏览器缓存请求页面时,一些WebBrowser(如Firefox)也会重新显示旧的输入值。创建一个注释为@WebFilter(servletNames={“facesServlet”})
(其中facesServlet
是facesServlet
的
,定义见web.xml
),在doFilter()
方法中基本包含以下内容:
HttpServletResponse hsr = (HttpServletResponse) response;
hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
hsr.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);