Punter Vicky
Punter Vicky

Reputation: 16992

Backing Bean Initialization

I have a variable in backing bean that needs to get reset to null whenever the associated page is opened using the relevant menu link. Is there a way to run a initialization code in the backing bean whenever the relevant menu link is clicked? Contsructor runs only the first time the menu link is clicked. I guess the bean is then retained in the jsf context and is not getting recreated. Is there a way to ensure a new object of that backing bean is created each time the menu link is clicked? Thanks!

Upvotes: 0

Views: 482

Answers (2)

Ken Chan
Ken Chan

Reputation: 90447

You have the following options:

1 . Change the bean to the request-scoped bean

2 . Use the action attribute to call the method on the backing bean to run the initialization code whenever the link is clicked , something like this:

 <h:commandLink action="#{myBean.init}" value="My Link" />

And myBean.init() contains the initialization code

Upvotes: 1

jjross
jjross

Reputation: 678

Couldn't you just put the bean in request scope?

Another option would be to use a setpropertyactionlistener on the menu. When the menu is clicked, set the value to "null".

Upvotes: 1

Related Questions