Menu Error ClassCastException DefaultSubMenu to UISubmenu

Post Reply
Aztek2010
Posts: 1
Joined: 31 May 2017, 08:03

12 Jun 2019, 22:03

Hello

have this problem in the moment create menu with Sapphire

Primefaces 7.0.3
JavaServerFaces 2.3
Sapphire 2.0
WildFly 16

ERROR MESSAGE

Code: Select all

14:35:04,151 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-1) Error Rendering View[/index.xhtml]: 
	java.lang.ClassCastException: org.primefaces.model.menu.DefaultSubMenu cannot be cast to org.primefaces.component.submenu.UISubmenu
	at org.primefaces.sapphire.component.SapphireMenuRenderer.encodeSubmenu(SapphireMenuRenderer.java:111)
	at org.primefaces.sapphire.component.SapphireMenuRenderer.encodeElement(SapphireMenuRenderer.java:96)
	at org.primefaces.sapphire.component.SapphireMenuRenderer.encodeElements(SapphireMenuRenderer.java:58)
	at org.primefaces.sapphire.component.SapphireMenuRenderer.encodeMarkup(SapphireMenuRenderer.java:48)
	at org.primefaces.component.menu.BaseMenuRenderer.encodeEnd(BaseMenuRenderer.java:109)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:595)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1654)
menu.xhtml

Code: Select all

<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:sm="http://primefaces.org/sapphire">

    <div id="layout-menu-container" class="layout-menu-container">
        <div id="layout-nano" class="nano">
            <div class="nano-content sidebar-scroll-content">
                <div class="layout-menu-wrapper">
                    <h:form id="menuform">
                        <sm:menu id="menuNavigation" model="#{menuView.model}" />
                    </h:form>
                </div>
            </div>
        </div>
    </div>

</ui:composition>
Could you please help me with this problem? :D

How can I create a new jar file or make changes to the jar file?

could you advise me

Sorry my english is bad :)

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

14 Jun 2019, 09:04

Thanks a lot for the sample. Fixed for next version. For now, please make the following change;
in SapphireMenuRenderer.jar

Code: Select all

...
protected void encodeSubmenu(FacesContext context, AbstractMenu menu, Submenu submenu, boolean megaMenuChild) throws IOException{
	ResponseWriter writer = context.getResponseWriter();
        String icon = submenu.getIcon();
        String label = submenu.getLabel();
        int childrenElementsCount = submenu.getElementsCount();
        boolean megaMenu = false;
        /****** Please see these lines *******/
        if(submenu instanceof UISubmenu) {
            Object mega = ((UISubmenu) submenu).getAttributes().get("mega");
            
            if (mega != null) {
                megaMenu = Boolean.parseBoolean(mega.toString());
            }
        }
        /*************************************/
        if (megaMenuChild) {
            writer.startElement("span", null);
            writer.writeAttribute("class", "layout-megamenu-submenu-text", null);
            writer.writeText(label, null);
            writer.endElement("span");
        }
To provide new jar please use mvn clean install -P distribute command

Johnson9T
Posts: 1
Joined: 02 Jul 2019, 08:35

02 Jul 2019, 08:37

aragorn wrote:
14 Jun 2019, 09:04
Thanks a lot for the sample. Fixed for next version. For now, please make the following change;
in SapphireMenuRenderer.jar

Code: Select all

...
protected void encodeSubmenu(FacesContext context, AbstractMenu menu, Submenu submenu, boolean megaMenuChild) throws IOException{
	ResponseWriter writer = context.getResponseWriter();
        String icon = submenu.getIcon();
        String label = submenu.getLabel();
        int childrenElementsCount = submenu.getElementsCount();
        boolean megaMenu = false [url=https://www.bluestacks.onl/][color=#000000]bluestacks[/color][/url];
        /****** Please see these lines *******/
        if(submenu instanceof UISubmenu) {
            Object mega = ((UISubmenu) submenu).getAttributes().get("mega");
            
            if (mega != null) {
                megaMenu = Boolean.parseBoolean(mega.toString());
            }
        }
        /*************************************/
        if (megaMenuChild) {
            writer.startElement("span", null);
            writer.writeAttribute("class", "layout-megamenu-submenu-text", null);
            writer.writeText(label, null);
            writer.endElement("span");
        }
To provide new jar please use mvn clean install -P distribute command bluestacks download
While the ClassCastException no longer occurs, the actual functionality of toggling a programmatic

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

08 Jul 2019, 08:43

I think the issue is resolved. Right?

Post Reply

Return to “Sapphire - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest