How to encode material icons programmatically

Forum rules
Please note that response time for technical support is within 3-5 business days.
Post Reply
bmoon
Posts: 24
Joined: 10 May 2016, 21:16

20 Feb 2017, 23:44

I'm trying to use a "<pu:menu ..." like the side bar menu and it expects "material" icons encoded like: "&#xe6e1" for its icons. I want to build that menu programmatically using a "defaultMenuModel". Question is, when I create a "DefaultSubMenu" and try to set the icon as the string "&#xe6e1" then this does not get encoded correctly for the HTML output -- i just get the string. What's the magic formatting for setting such an icon?

I tried using unicode: "\ue6e1" but that's not right of course.

UPDATE: Ok, I still don't know how to encode the numeric codes, however I did find that I could simply use the "material" names -- so to get those names I used this web site: https://glyphsearch.com/?library=material

Selecting the material glyph set and then searched for an icon. Then you just use those names for your icon name rather than the numerical codes.

roabol
Posts: 34
Joined: 04 Oct 2010, 16:04
Location: Brazil

18 Aug 2017, 19:11

Tks!!!!!!!
PrimeFaces Elite 12.0.5
Ultima 6.1.0
Apache NetBeans IDE 18
Windows 11
Payara Server Open Source Edition 6.2023.7
FF, Chrome, Edge, Opera

Hamsterbau
Posts: 409
Joined: 28 Dec 2011, 17:44

07 Sep 2017, 12:42

I do not really understand why so "cryptical names" will be used (also in the menu implementation). In version 1.0.9 (perhaps earlier) it is possible to use the names with ui-icon class:

Code: Select all

<i class="ui-icon ui-icon-3d-rotation"></i>
Primefaces 8.0.7 (PF Extensions 8.0)
JSF: Mojarra 2.3.2 (Spec 2.3) - running on WildFly 22

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

19 Sep 2017, 09:40

Please make the following change in UltimaMenuRenderer.java;

Code: Select all

protected void encodeItemIcon(FacesContext context, String icon) throws IOException {
        if(icon != null) {
            ResponseWriter writer = context.getResponseWriter();

            writer.startElement("i", null);
            
            if(icon.contains("fa fa-")) {
                writer.writeAttribute("class", icon, null);
            }
            else {
                writer.writeAttribute("class", "material-icons", null);
                writer.write(icon); // Please use write instead of writeText
            }
            
            writer.endElement("i");
        }
    }


Post Reply

Return to “Ultima - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests