Page 1 of 1

Can't destroy view scoped managed bean when navigating through menu

Posted: 04 Mar 2018, 21:45
by Proyecto SIAM
Hi.
I'm using a view scoped managed bean and the annotation @PreDestroy to execute a method when navigating outside one page. I got some icons in the topbar and when I navigate through them to other pages, JSF detects the navigation (using faces-redirect=true) and executes the method. But when I navigate through the menu JSF doesn't detect the navigation thus not executing the annotated method.
This is the code for the menu.

Code: Select all

<pa:tabMenu>
            <pa:tab icon="fa fa-anchor" title="Menu">
                <h:form id="frmMenu">
                    <pa:menu widgetVar="miMenu" model="#{menu.miMenu}"/>
                </h:form>
            </pa:tab>
</pa:tabMenu>  
The menu model miMenu is filled from back-end like this:

Code: Select all

DefaultSubMenu submenu = new DefaultSubMenu("");
DefaultMenuItem item;
for(Modulo modulo : modulos){
    item = new DefaultMenuItem();
    item.setValue(modulo.getName());
    item.setOutcome(modulo.getUrl());
    item.setIcon(modulo.getIcon());
    item.setAjax(false);
    submenu.addElement(item);
  }
Here is an example of one of the elements in the topbar :

Code: Select all

<div class="logo">
            <h:form>
                <h:commandLink action="index?faces-redirect=true" 
                               title="Go to Index">
                    <h:graphicImage value="resources/images/logo.png" />
                </h:commandLink>
            </h:form>
 </div>
How can I configure the menu so JSF can detect the navigation?

Re: Can't destroy view scoped managed bean when navigating through menu

Posted: 07 Mar 2018, 08:25
by mert.sincan
Could you please try it with p:menu instead of pa:menu or pa:* component(without Barcelona theme/layout)?

Re: Can't destroy view scoped managed bean when navigating through menu

Posted: 08 Mar 2018, 18:29
by Proyecto SIAM
Hello.
I have tried without the template elements:

Code: Select all

<h:form id="frmMenu">
     <p:menu widgetVar="miMenu" model="#{menu.miMenu}"/>
</h:form>
And even configuring the outcome of each element (including faces-redirect attribute) :

Code: Select all

item.setOutcome(modulo.getUrl() + "?faces-redirect=true");
But the result is the same.

Re: Can't destroy view scoped managed bean when navigating through menu

Posted: 12 Mar 2018, 14:15
by mert.sincan
This is not a Layout or Theme issue. Please use PrimeFaces core forum.

Also, you can try the following code;

Code: Select all

item.setCommand("#{bean.navigate}");

//bean
public String navigate() {
   return "test.xhtml??faces-redirect=true";
}

Re: Can't destroy view scoped managed bean when navigating through menu

Posted: 12 Mar 2018, 22:36
by Proyecto SIAM
Configuring the MenuItem with setCommand solved the problem.

Even solved another problem I had when catching ViewExpiredException.

Thanks. :D

Re: Can't destroy view scoped managed bean when navigating through menu

Posted: 13 Mar 2018, 06:59
by mert.sincan
Glad to hear, thanks a lot for the update!