0
votes

I am noticing that when I use h:commandButton to call an actionlistener method from a managedbean, managed beans that are used on current view page, are re-instantiated on their own. Now since my data from those beans was already fetched and added to the view, there is no need to re-instantiate those beans, but JSF does that.

I used the following code to call a method,

<h:commandButton value="Increment" actionListener="#{channelController.increment()}"/>

I found that another managed bean UserChannelsList is instantiated on its own.. I am not submitting any data to this bean, or using any of its method, neither the view needs to fetch any properties from this bean. Why does JSF instantiates all these beans used in the view, on its own ?

EDIT

It is not due to actionListener attribute, even if I remove this attribute & just click on the commandButton then too the managed bean's are instantiated on their own!

1

1 Answers

0
votes

All managed beans which are referenced in the entire view or as managed property by one of the beans referenced in the view will be created if not in the current scope yet. So surely your view must have either directly or indirectly referenced it. If you can't immediately seem to find it in your code base, put a breakpoint on the bean's constructor and check the call stack to figure the initiator.

This has nothing to do with using action listeners (which is by the way fishy in the context as you have there without a real action method, read on about Differences between action and actionListener).