when is a bean initialized? I used @RequestScoped managed bean annotation.
I have a page - products.xhtml and I am redirecting on the same page depending on the version a clicks.
For example, user clicks 2019.000, it redirects to the same page~ /products.xhtml?faces-redirect=true&ver=2019.000
My problem is I have a dialog that opens when a user clicks on a p:commandLink. The bean needed to populate the dialog's contents is DownloadView.java::getRoot(). Here's a snippet of my DownloadView.java.
@ManagedBean(name = "DownloadView")
@ViewScoped
public class DownloadView implements Serializable {
private TreeNode root;
private String path;
public TreeNode getRoot() {
DownloadBI downloadBI = new DownloadBI(modifyPath(this.path));
this.root = downloadBI.getFilesTreeNode();
if (root.getChildCount() != 0)
this.root.getChildren().get(0).setExpanded(true);
return this.root;
}
. . .
The default selection when page loads is 2020.000. The dialog works perfectly fine with the correct target links when loaded from the default selection 2020.000. But, when I redirect to 2019.000 and try to open a dialog, it seems that the bean retained the data from 2020.000. Here is a snippet of my p:commmandLink calling the dialog from products.xhtml.
<p:commandLink value="#{startup.name}" title="#{startup.name}"
process="@form" update=":download-form:downloadPanel"
oncomplete="PF('downloadDialog').show()" >
<f:setPropertyActionListener target="#{DownloadView.path}" value="#{startup.url}"/>
</p:commandLink>
I was assuming that the value of startup.url should change every time the commandlink is clicked. It does but, its the same value from 2020.000. While testing its behavior, I noticed that the form id is the same from 2020.000 and 2019.000.
From chrome source:
j_idt161:0:j_idt163:1:download-view
is the same when selecting from 2019.000. They should be different since they have different urls.
I thought that this is scoping issue, but I tried all scopes. But, it is still not working. I am thinking that I should create my DownloadView.java bean only when the commandLink is clicked, and when the dialog is closed, it should also be destroyed. But, I am not sure how to do this as well. :(
I have been debugging this for days now and I'm stuck. I hope someone could give some ideas how to resolve this. I am new to JSF/Primefaces, by the way. Please help!