Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:33:34+00:00 2026-06-15T19:33:34+00:00

How can I add links to <p:submenu /> for use with <p:megaMenu> ? For

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:33:36+00:00Added an answer on June 15, 2026 at 7:33 pm

    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:

    <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 id="megaMenu">
                <p:submenu label="Home" url="/" styleClass="homeLink" />
                <p:submenu label="Category" url="/cats" styleClass="catLink">
                    <p:column>
                        <p:submenu label="Category 1" styleClass="cat1Link">
                            <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>
            <script type="text/javascript">
            $(function(){
                $(".homeLink a:first").attr('href', "#{request.contextPath}/");
                $(".catLink a:first").attr('href', "#{request.contextPath}/cats");
                $(".cat1Link").click(function(){
                    window.location.href="#{request.contextPath}/cats/cat1";
                }).css('cursor','pointer');
            });
            </script>
        </ui:define>
    
    </ui:composition>
    

    What I did here was:

    1) I defined every <p:submenu> with an exclusive styleClass

    2) If the <p:submenu> is on the first line, I changed the <a>‘s href attribute to my link after the DOM is ready:

    $(function(){
        $(".homeLink a:first").attr('href', "#{request.contextPath}/");
        $(".catLink a:first").attr('href', "#{request.contextPath}/cats");
    });
    

    3) If the <p:submenu> is part of a menu, I created an onclick attribute and customized the cursor to pointer since there’s no <a> tag there.

    $(".cat1Link").click(function(){
        window.location.href="#{request.contextPath}/cats/cat1";
    }).css('cursor','pointer');
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I add links in google chart api? For example, How could I add
I wrote library which can add and update objects in salesforce. I use beatbox
i was wondering how can i add images to links with css that is
I am not sure how i can add links to my images to make
I'm making a UI where the user can add and store links to their
I want to create a customized submenu where i can add an about page
I would like to add links on every date in my calendar. For example,
Can I add links in comments to a code block in Visual studio ?
I need to make a table such that the user can add attachment links
I can add and remove the last line in my dynamic form and calculate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.