I'm having an issue with a form that I have. The form allows users to enter info into some textboxes and then there are 2 buttons - Search and Reset.
Form code:
<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>
The problem I'm having is that if I click the search button, it takes me to the results page and if I go back to the search page, it still has the data that I searched with in the text fields because the bean is session scoped. I want to be able to click the Reset button and have the data in the text fields clear.
Currently with the code below, if I click the Reset button, The search button no longer works and in the firebug console it gives me this error
<?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>
If I remove the onclick="clearForm(this.form);"
from the second p:commandButton
, the form works fine.
Any ideas why calling a JS function would make the view expire?
Publication Bean:
@ManagedBean(name="pubBacker")
@SessionScoped
public class Publication {
public Publication() {}
public void clearEntries() {
new Publication();
}
}