I saw other questions regarding calling the bean constructor and ViewScope, and I still have difficulties. The problem I see involves two specific pages in my application. The first is dataTable (at the moment it is filled with randomly generated data, but ultimately calls up the database), the second page is a fairly simple display page, on which information from the selected row is displayed in the form for editing or viewing - this is my detail.xhtml page detail.xhtml . This is a bean problem for this page; its constructor is called twice: first, when I go to the page, again, when I press commandButton, whether to send changes or cancel the changes, it does not matter, the second bean constructor is created by the detail.xhtml constructor.
My bean is @ViewScoped importing javax.faces.bean.ViewScoped . A few other details that may make a difference, but if they do, I don't understand why: my UserDetailBean.java inherits from the bean base (which I originally called UIBaseBean.java). Now my UIBaseBean @RequestScoped . As far as I understand, this should not change, because my UserDetailBean @ViewScoped , please correct me if I am wrong.
Another detail that may make a difference is setting the variable in the constructor of both the UIBaseBean and the UserDetailBean. I want to show the user's location on the toolbar at the top of my pages. For this purpose, I created a variable in UIBaseBean:
protected String toolbarDescription;
I also provided setter and getter in a UIBaseBean. In the UIBaseBean constructor, I define a variable:
toolbarDescription = "fix me";
This definition is just so that I know to override the variable in the backup bean for any specific page in my application. In my UserDetailBean, I assign a new value to describe the String toolbar. This value is displayed on the detail.xhtml page. Otherwise, the bean page for my detail.xhtml is very simple, it receives and sets the properties for displaying data in the form on the detail.xhtml page.
The details page is configured so that navigation to it occurs with redirection, and disconnection (by pressing the commandButton button) occurs with redirection. I tried using faces-config navigation rules with and without redirects and hidden navigation with and without redirects, but the UserDetailBean constructor is always called twice.
Oh, I set a breakpoint in the toolbar variable in my UserDetailBean constructor, which stops the program twice: when the page is first called, and again after I click the CommandButton button on the details page.
From what I described, can someone tell me why my constructor is called twice? Am I developing my bean incorrectly, or is the problem deeper in my application?
import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.event.ActionEvent; import [package name].UIBaseBean; import java.util.Locale; import javax.faces.bean.ManagedProperty; @ManagedBean @ViewScoped public class UserDetailBean extends UIBaseBean { @ManagedProperty(value = "#{param.action}") private String action; private String firstName; private String lastName; private String jobTitle; private String DOH; private String location; private String status; private String comments; @ManagedProperty(value = "#{param.id}") private String id; private String tabTitle; private boolean editMode; private boolean viewMode; private ClUserDetail dBUserDetail; public UserDetailBean() { toolbarDescription = CoreMsgBundle.getMessageFromResourceBundle("UserDetail", Locale.ENGLISH); }