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

Post Reply
Proyecto SIAM
Posts: 5
Joined: 24 Oct 2017, 18:37

04 Mar 2018, 21:45

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?

User avatar
aragorn
Posts: 3284
Joined: 29 Jun 2013, 12:38

07 Mar 2018, 08:25

Could you please try it with p:menu instead of pa:menu or pa:* component(without Barcelona theme/layout)?

Proyecto SIAM
Posts: 5
Joined: 24 Oct 2017, 18:37

08 Mar 2018, 18:29

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.

User avatar
aragorn
Posts: 3284
Joined: 29 Jun 2013, 12:38

12 Mar 2018, 14:15

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";
}

Proyecto SIAM
Posts: 5
Joined: 24 Oct 2017, 18:37

12 Mar 2018, 22:36

Configuring the MenuItem with setCommand solved the problem.

Even solved another problem I had when catching ViewExpiredException.

Thanks. :D

User avatar
aragorn
Posts: 3284
Joined: 29 Jun 2013, 12:38

13 Mar 2018, 06:59

Glad to hear, thanks a lot for the update!

Post Reply

Return to “Barcelona - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest