Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 如何重新显示具有空字段的表单?_Jsf_Jsf 2_Javabeans - Fatal编程技术网

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

我正在使用托管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>

身份证件
名称

将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);