Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dont fill request scoped bean

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.

like image 799
Sebastian Hoffmann Avatar asked Feb 02 '26 15:02

Sebastian Hoffmann


1 Answers

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.

like image 161
Elias Dorneles Avatar answered Feb 04 '26 05:02

Elias Dorneles