How can I add links to <p:submenu /> for use with <p:megaMenu>?
For example:
<!DOCTYPE html>
<ui:composition xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
template="/pages/template/homeTemplate.xhtml">
<ui:define name="content">
<p:megaMenu>
<p:submenu label="Home" url="/" />
<p:submenu label="Category" url="/cats">
<p:column>
<p:submenu label="Category 1" url="/cats/cat1">
<p:menuitem value="Item 1" url="/cats/cat1/item1"/>
<p:menuitem value="Item 2" url="/cats/cat1/item2"/>
<p:menuitem value="Item 3" url="/cats/cat1/item3"/>
</p:submenu>
</p:column>
</p:submenu>
</p:megaMenu>
</ui:define>
</ui:composition>
The <p:submenu /> doen’t have the url attribute, so it will be ignored, what can I do instead?
I was facing this issue, I found lot’s of people saying that it was not possible because primefaces doesn’t support it, but there’s a workaround if you don’t mind using a bit of javascript:
What I did here was:
1) I defined every
<p:submenu>with an exclusivestyleClass2) If the
<p:submenu>is on the first line, I changed the<a>‘shrefattribute to my link after the DOM is ready:3) If the
<p:submenu>is part of a menu, I created anonclickattribute and customized the cursor to pointer since there’s no<a>tag there.This resulted in the menu that I needed, and of course, will not work if javascript is disabled, but now the menu will work with javascript enabled browsers.