VERONA layout have this function?

Post Reply
bacon88
Posts: 67
Joined: 29 Aug 2012, 08:36
Location: SiChuang,China

21 May 2020, 11:22

In omega layout,it hava <po:menu> to implement Programmatic Menu,but in VERONA layout,I can't find out it .How could I make a Programmatic Menu in Verona Layout?
Thanks for help.
jdk1.8.0_202 & Java EE 8
primefaces 8.0
Mojarra 2.3.9
GlassFish Server 5.1.0

aragorn
Posts: 4042
Joined: 29 Jun 2013, 12:38

03 Jun 2020, 11:19

Yes, you can make it. Please see;

Code: Select all

//MenuView.java
...

@Named
@RequestScoped
public class MenuView {

    private MenuModel model;

    @PostConstruct
    public void init() {
        model = new DefaultMenuModel();

        //First submenu
        DefaultSubMenu firstSubmenu = DefaultSubMenu.builder()
                .label("Dynamic Submenu")
                .build();

        DefaultMenuItem item = DefaultMenuItem.builder()
                .value("External")
                .url("http://www.primefaces.org")
                .icon("pi pi-home")
                .build();
        firstSubmenu.getElements().add(item);

        model.getElements().add(firstSubmenu);

        //Second submenu
        DefaultSubMenu secondSubmenu = DefaultSubMenu.builder()
                .label("Dynamic Actions")
                .build();

        item = DefaultMenuItem.builder()
                .value("Save")
                .icon("pi pi-save")
                .command("#{menuView.save}")
                .build();
        secondSubmenu.getElements().add(item);

        item = DefaultMenuItem.builder()
                .value("Delete")
                .icon("pi pi-times")
                .command("#{menuView.delete}")
                .ajax(false)
                .build();
        secondSubmenu.getElements().add(item);

        item = DefaultMenuItem.builder()
                .value("Redirect")
                .icon("pi pi-search")
                .command("#{menuView.redirect}")
                .build();
        secondSubmenu.getElements().add(item);

        model.getElements().add(secondSubmenu);
    }

    public MenuModel getModel() {
        return model;
    }

    public void save() {
        addMessage("Success", "Data saved");
    }

    public void update() {
        addMessage("Success", "Data updated");
    }

    public void delete() {
        addMessage("Success", "Data deleted");
    }

    public void addMessage(String summary, String detail) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

Code: Select all

//menu.xhtml
<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:pv="http://primefaces.org/verona">

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

</ui:composition>
Best Regards,

Post Reply

Return to “Verona - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests