I am trying to implement a program that populates a dataTable on one page, and displays the details of the the selected row on another page for either viewing or editing. The backing bean for my detail page (call it DetailBackingBean) is ViewScoped. This bean is pretty straight forward, except for one variable which I will talk about the bean is all getters and setters with some basic functionality for enabling/disabling inputText boxes. This bean also sets the value of a variable in the constructor. This variable is defined in a parent bean I import into my DetailBackingBean (call the parent bean BaseBean).
Okay, BaseBean is very simple. It defines this one variable (a protected
String) and provides the getter and setter for it. This variable is called toolbarDescription. BaseBean is @RequestScoped.
When I put a breakpoint in my DetailBackingBean on the variable definition for toolbarDescription (which is in my constructor) I note that the DetailBackingBean constructor is called when I navigate from my dataTable page to my detail page. So far so good. Whether or not the detail page is set to "view" (inputText boxes are disabled so information is displayed only) or to "edit" (inputText boxes are enabled so data can be edited) - whenever I press the commandButton to "submit changes" or to "cancel" the DetailBackingBean constructor is called a second time.
Is this happening because the BaseBean is @RequestScoped? Is there a way to keep the BaseBean as a "@ManagedBean" in "@RequestScoped" and not have the UserDetailBean constructor called twice? I was able to make this work by making BaseBean abstract and removing the "@ManagedBean" and "@RequestScoped" annotations, but that is not how my boss wants this to work. Can anyone provide insight as to why the constructor is called twice? Any suggestions for correcting this behavior without going the abstract route?
Do faces-config navigation rules (with or without <redirect /> tags) have any effect on this?