Dynamic po:menu with IDs

Post Reply
LGiusti84
Posts: 8
Joined: 02 Jan 2018, 16:08

17 Jan 2018, 00:24

Hi,

I've made a dynamic menu, but I found my self with a problem, I cannot set the IDs to the elements.
aragorn wrote:
21 Nov 2016, 09:07
I think this link can help to you for dynamic po:menu; http://www.primefaces.org/showcase/ui/menu/menu.xhtml (Please see Programmatic Menu section)
I used the example code suggested in the another post, but it was of no use.

----

This would be a quick representation of my code (actually tested)

xhtml:

Code: Select all

...
    <po:menu id="mainMenu" model="#{myBean.mainMenuModel}" />
...

Java bean:

Code: Select all

@ManagedBean
public class MyBean {

    private MenuModel model;

    @PostConstruct
    public void init() {
        model = new DefaultMenuModel();
        // model = new DynamicMenuModel(); // this option does not work either

        // Submenu
        DefaultSubMenu mySubmenu = new DefaultSubMenu("Dynamic Submenu");
        mySubmenu.setId("mySubmenu");

        DefaultMenuItem item = new DefaultMenuItem("External");
        item.setUrl("http://www.primefaces.org");
        item.setId("myMenuItem");
        mySubmenu.addElement(item);

        model.addElement(mySubmenu);
    }

    public MenuModel getMainMenuModel() {
        return model;
    }
}

this generates:

ul #mainMenu
....|__ il #mainMenu_0
........|__ ul
............|__ il #mainMenu_0_0

myMenuItem and mySubmenu are nowhere to be seen.

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

09 Feb 2018, 13:37

I think this issue is related to PrimeFaces core. Could you please try it with p:menu component without Omega Layout? We create unique ids for dynamic menu items in core.

LGiusti84
Posts: 8
Joined: 02 Jan 2018, 16:08

15 Feb 2018, 20:03

I can confirm that, this is an issue of primefaces core. For what I read (here and on stackoverflow) this dates from primefaces 4 (almost 4,5 years ago?), even though we set the IDs with setId() method, they get overwritten with primefaces generated IDs (based on the menu id) when creating the code for rendering.

We've tried with dynamic menu items, default menu items and several other suggestions, ideas and so on, but since, moved on. We had adopted some bad-practices to avoid losing more time on this issue and continue with development and QA testing.


Again, did tested it some time ago with both p:menu and po:menu (with several combinations of defaultMenu*, DynamicMenu*, ..., and other ideas) and both failed to assign the given IDs.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest