我的表格有问题。该表单允许用户在一些文本框中输入信息,然后有 2 个按钮 - 搜索和重置。
表格代码:
<h:outputText value="Search by Author Name" styleClass="p" />
<div class="investigatorTab">
<h:outputLabel for="firstName" rendered="true" value="First Name" />
<h:inputText value="#{pubBacker.firstName}"></h:inputText>
<h:outputLabel for="lastName" rendered="true" value="Last Name" />
<h:inputText value="#{pubBacker.lastName}"></h:inputText>
</div>
<div class="buttons">
<p:commandButton value="Submit" styleClass="submitButton" action="#{pubBacker.submit}" update="tabs" />
<p:commandButton value="Reset" type="button" actionListener="#{pubBacker.clearEntries}" onclick="clearForm(this.form);" />
</div>
我遇到的问题是,如果我单击搜索按钮,它会将我带到结果页面,如果我返回搜索页面,它仍然具有我在文本字段中搜索的数据,因为 bean 是会话范围。我希望能够单击重置按钮并清除文本字段中的数据。
目前使用下面的代码,如果我点击重置按钮,搜索按钮不再起作用,并且在萤火虫控制台中它给了我这个错误
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class javax.faces.application.ViewExpiredException</error-name><error-message><![CDATA[viewId:/ccadmin/pubManagement.xhtml - View /ccadmin/pubManagement.xhtml could not be restored.]]></error-message></error></partial-response>
如果我onclick="clearForm(this.form);"
从第二个中删除p:commandButton
,表格可以正常工作。
任何想法为什么调用 JS 函数会使视图过期?
发布 Bean:
@ManagedBean(name="pubBacker")
@SessionScoped
public class Publication {
public Publication() {}
public void clearEntries() {
new Publication();
}
}