1

I'm trying to get the applicationContext of my web app which is defined on jboss-web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/Tesoreria-WEB</context-root>
    <max-active-sessions>300</max-active-sessions>
</jboss-web>

Is there a way to get that String Tesoreria-WEB? I need it because my menus aren't adding that part of the url anymore after upgrading from 3.5 to 7.0, so im gonna get that context and add it before they are created. I had tried with:

    System.out.println("Application name: "+ PrimeRequestContext.getCurrentInstance(FacesContext.getCurrentInstance()).getApplicationContext());

but no success, is there a way or should I add it manually? thanks!

By the way I think they stopped adding correctly the url after upgrading to 7.0 from 3.5 because of https://github.com/primefaces/primefaces/wiki/Migration-Guide breaking changes from 6.2 to 7.0 says "Button/Link/MenuItem: The url/href attribute isn't automatically prepended by contextPath anymore. Use the outcome attribute for referencing JSF views in the same application or manually prepend url/href with #{request.contextPath}. See https://github.com/primefaces/primefaces/issues/3506." But I don't understand what does that mean.

how I expect my url to be built (notice Tesoreria-WEB on the url): http://10.13.44.48:8483/Tesoreria-WEB/XHTML/boxes/boxesMassive.xhtml

how they are being built since I upgraded to 7.0 (this brings 404): http://10.13.44.48:8483/XHTML/boxes/boxesMassive.xhtml

I dynamically made my menuBar on the ManagedBean and on the xhtml I call reference it like this, that's all no menuItems no things like that all is made on the ManagedBean:

<p:menubar id="menuBar" binding="#{menuMB.menuBar}"
                    autoDisplay="false" styleClass="cds-menu-mainmenu"
                    rendered="#{plantillaGeneralMB.habilitarMenu}" />

This is how we dynamically make the menu, while debugging I found where exactly they get their url, its a bit down there I commented where in English:

this Node objects are from org.w3c.dom.Node

private List<SubMenuItem> cargarSubmenus(Node pNodeMenu,
            List<String[]> lJerarquiaTemp, String[] tituloPadre) {

        Node nodeSubMenu = null;
        // Obtener la lista de hijos de este nodo.
        NodeList childNodes = pNodeMenu.getChildNodes();

        int sizeList = childNodes.getLength();
        List<SubMenuItem> lSubmenus = new ArrayList<>();
        SubMenuItem subMenu = null;
        lJerarquiaTemp.add(tituloPadre);

        for (int i = 0; i < sizeList; i++) {

            // Obtener el hijo de este nodo correspondiente al indice indicado.
            nodeSubMenu = childNodes.item(i);

            // Verificar que efectivamente este nodo sea un Submenu
            if (nodeSubMenu.getNodeName().equals("SUBMENU")) {

                // Verificar que el nodo tenga atributos.
                if (nodeSubMenu.hasAttributes()) {

                    NamedNodeMap map = nodeSubMenu.getAttributes();
                    // Obtener codigo.
                    Node codigo = map.item(0);
                    // Obtener titulo
                    String titulo = nodeSubMenu.getChildNodes().item(1)
                            .getTextContent();
                    // THIS IS THE URL **********************
                    String url = nodeSubMenu.getChildNodes().item(3)
                                .getTextContent();
// Im having to add "/Tesoreria-WEB" + url to make my urls well constructed, no idea what changed so much from 3.5 to 7.0 here if someone knows how to make it work without adding this manually its appreciated
                    subMenu = new SubMenuItem(codigo.getTextContent(), titulo,
                            "/Tesoreria-WEB"+url);




                    System.out.println("Application name: "+ PrimeRequestContext.getCurrentInstance(FacesContext.getCurrentInstance()).getApplicationContext());


                    subMenu.setlJerarquia(lJerarquiaTemp);
                    String[] menuInfo = { codigo.getTextContent(), titulo, url };
                    // Si esta nodo tiene mas hijos llamar recursivamente este
                    // metodo.

                    if (nodeSubMenu.getChildNodes().item(5) != null
                            && nodeSubMenu.getChildNodes().item(5)
                                    .getNodeName().equals("SUBMENU")) {
                        subMenu.setlSubmenus(cargarSubmenus(nodeSubMenu,
                                subMenu.getlJerarquia(), menuInfo));
                    }

                    if (nodeSubMenu.getChildNodes().item(5) != null
                            && nodeSubMenu.getChildNodes().item(5)
                                    .getNodeName().equals("TABS")) {
                        subMenu.setlTabs(cargarTabs(nodeSubMenu.getChildNodes()
                                .item(5)));
                    }

                    // Adicionar este submenu y sus hijos a la lista de submenus
                    // del nodo original.
                    lSubmenus.add(subMenu);

                }
            }
        }

        return lSubmenus;

    }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BugsForBreakfast
  • 712
  • 10
  • 30

2 Answers2

2

The way to get that context-root of the application in JSF is:

FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();

For more info see Get the web application context path from META-INF/context.xml to produce an outcome for navigating

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
BugsForBreakfast
  • 712
  • 10
  • 30
1

Yes what they mean is do this...

<p:menuitem value="my URL" url="#{request.contextPath}/boxes/boxesMassive.xhtml" />
Melloware
  • 10,435
  • 2
  • 32
  • 62
  • sorry mate I did a mistake on my question, not using those menu items that was a test I was doing, im actually using just a menuBar object on the ManagedBean, that one has the submenus and its items, and on the xhtml I just have the menuBar referenced, my bad ;p, please help me find a way to get root context, I also updated question hehe, but thats also helpful I didn't know what they ment too – BugsForBreakfast Jul 19 '19 at 20:58