I have a request scoped bean which is filled with various properties from a form. These properties are then used to update another view scoped bean. Now I want to give the user the possibility to the reset the form in such a way that all form fields are holding the values they had when the page was loaded the first time. These values are defined through the bean itself:
@ManagedBean
@RequestScoped
public class ItemSearchBean {
private Rarity minRarity = Rarity.None;
private Rarity maxRarity = Rarity.None;
...
}
Notice though that the form submiting button actually invokes a ajax request, therefor no full page reload goes on.
The submitting button:
<p:commandButton value="Search"
actionListener="#{itemSearchBean.refreshTable}"
update="itemTable,notify"/>
I already tried to use a simple reset button, but it only reseted the form to the last submitted values:
<p:commandButton type="reset" value="Reset"/>
One has to somehow ask the server for a fresh new bean (or prevent it to fill the bean), but I have no clue how to do this.
You should be able to do that with a plain HTML link to the same view:
<a href="yourpage.xhtml">Reset</a>
or let JSF create the link for you:
<h:link value="Reset" />
This way you'll have a new GET request that will create a new UIViewRoot, just like if you were accessing the same view in a new browser tab.
If you want a button instead, you can use an h:button
<h:button value="Reset" />
This button will rely on a Javascript that will reload the page on click.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With