Menú dinámico / Dynamic menu

Post Reply
elfiguero
Posts: 1
Joined: 18 Jul 2018, 23:39

24 Jul 2018, 17:08

Buenos días a todos.
Soy nuevo por aquí. Recién compramos la plantilla serenity para primefaces y necesito hacer el menú de forma dinámica, alguien me puede ayudar con esto.
De antemano muchas gracias.
-------------------------
Good morning to all.
I'm new around here. We just bought the serenity template for primefaces and I need to do the menu dynamically, someone can help me with this.
Beforehand thank you very much.

huseyinT
Posts: 123
Joined: 27 Mar 2016, 13:05

27 Jul 2018, 10:18

You could look the overlay example for a menu dynamically :

https://www.primefaces.org/showcase/ui/menu/menu.xhtml

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

27 Jul 2018, 10:29

You can use model attribute of pm:menu. Exp;

Code: Select all

//sidebar.xhtml
...
<h:form id="menuform">
          <pm:menu model="#{testView.model}"></pm:menu>
 </h:form>
...

Code: Select all

...
@ManagedBean
public class TestView {

    private MenuModel model;

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

        //First submenu
        DefaultSubMenu firstSubmenu = new DefaultSubMenu("Dynamic Submenu");
        firstSubmenu.setIcon("home");

        DefaultMenuItem item = new DefaultMenuItem("External");
        item.setUrl("http://www.primefaces.org");
        item.setIcon("close");
        firstSubmenu.addElement(item);

        model.addElement(firstSubmenu);

        //Second submenu
        DefaultSubMenu secondSubmenu = new DefaultSubMenu("Dynamic Actions");
        secondSubmenu.setIcon("home");

        item = new DefaultMenuItem("Save");
        item.setIcon("home");
        item.setCommand("#{testView.save}");

        secondSubmenu.addElement(item);

        item = new DefaultMenuItem("Delete");
        item.setIcon("home");
        item.setCommand("#{testView.delete}");
        item.setAjax(false);
        secondSubmenu.addElement(item);

        item = new DefaultMenuItem("Redirect");
        item.setCommand("#{testView.redirect}");
        secondSubmenu.addElement(item);

        model.addElement(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);
    }
}


Post Reply

Return to “Serenity - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest