private void generateUniqueIds(List<MenuElement> elements, String seed) {
        if (elements == null || elements.isEmpty()) {
            return;
        }

        int counter = 0;
        boolean root = (seed == null);

        for (MenuElement element : elements) {
            // #1039 check if ID was already manually set
            String id = element.getId();
            // set coordinates as a fallback for RequestScoped models (PF < 11 did this)
            String coordinates = root ? String.valueOf(counter++) : seed + ID_SEPARATOR + counter++;
            if (LangUtils.isBlank(id)) {
                // prepend root elements with "_" to distinguish them from others in MenubarRenderer#encodeSubmenuIcon
                String submenu = root ? ID_SEPARATOR : Constants.EMPTY_STRING;
                // ID is _ then UUID then | then Coordinates
                String menuId = String.format("%s%s%s%s", submenu, UUID.randomUUID(), COORDINATES_SEPARATOR, coordinates);
                element.setId(menuId);
            }

            if (element instanceof MenuGroup) {
                generateUniqueIds(((MenuGroup) element).getElements(), coordinates);
            }
        }
    }
Base implementation for model of a programmatic menu
primefaces/src/main/java/org/primefaces/model/menu/BaseMenuModel.java