Krishna
Krishna

Reputation: 363

JSF Component state of <h:selectOneMenu> didnt change for page refresh

I would like to get my JSF Component Dropdown boxes initialized for each page refresh. I already knows that JSF maintains the previous state, but is there any way that i can re-initialize the <h:selectOneMenu> Component on each page refresh. My Backing bean is SessionScoped and I cannot change it, since i am using <f:ajax> tag to fire a backing bean method on each onChange event of this dropdown boxes. Please help me to the solve this issue.

Upvotes: 0

Views: 1195

Answers (2)

BalusC
BalusC

Reputation: 1108642

since i am using <f:ajax> tag to fire a backing bean method on each onChange event of this dropdown boxes

For among others exactly this reason, the view scope is been invented. Put the bean in the view scope instead.

@ManagedBean
@ViewScoped
public class Bean {
    // ...
}

Each browser window/tab will get its own view scoped bean and every page refresh will recreate it. It'll also immediately fix the potential major trouble caused by unintuitive page behaviour when the user has the same page open in different browser windows/tabs in the same session while you're using a session scoped bean.

See also:

Upvotes: 0

Mr.J4mes
Mr.J4mes

Reputation: 9266

I think this article can solve your issue. You simply need to reset the property that's binded to that <h:selectOneMenu> before render the view.

Upvotes: 1

Related Questions