private void buildStateModel() {
    stateModel = new DynamicMenuModel();
    DefaultMenuItem homeItem = new DefaultMenuItem();
    homeItem.setAjax(false);
    homeItem.setValue("home");
    homeItem.setId(
        FacesContext.getCurrentInstance().getViewRoot().createUniqueId() + "_state_home");
    homeItem.setImmediate(true);
    homeItem.setCommand("#{stateController.clearStateAndGoHome}");
    stateModel.addElement(homeItem);
    for (StateItem stateItem : stateItens) {
      DefaultMenuItem item = new DefaultMenuItem();
      item.setAjax(stateItem.isAjax());
      item.setGlobal(stateItem.isGlobal());
      item.setResetValues(stateItem.isResetValues());
      item.setTitle(stateItem.getTitle());
      item.setImmediate(stateItem.isImmediate());
      item.setValue(getItemValue(stateItem.getValue()));
      if (stateItem.getOncomplete() != null && !"".equals(stateItem.getOncomplete())) {
        item.setOncomplete(stateItem.getOncomplete());
      }
      item.setId(FacesContext.getCurrentInstance().getViewRoot().createUniqueId() + "_state");
      if (stateItem.getOutcome() != null && !"".equals(stateItem.getOutcome())) {
        item.setIncludeViewParams(true);
        StringBuilder url = new StringBuilder(stateItem.getOutcome());
        if (stateItem.isAddEntityIdParam()) {
          url.append("?id=").append(((BaseEntity) stateItem.getEntity()).getId());
        }
        if (url.toString().contains("?")) {
          url.append("&pullState=true");
        } else {
          url.append("?pullState=true"); // tell statePusher to not call preRenderView event
        }
        url.append("&itemIndex=").append(stateItens.indexOf(stateItem));
        item.setUrl(url.toString());
      } else { // if has not outcome set command, note that they are muttually exclusive:
               // http://stackoverflow.com/questions/16437336/using-both-setactionexpression-and-seturl-on-menuitem-object-is-not-working
        item.setCommand("#{stateController.pullStateItem(" + stateItens.indexOf(stateItem) + ")}");
      }
      if (!"".equals(stateItem.getUpdate())) {
        item.setUpdate(stateItem.getUpdate());
      }

      if (stateItens.indexOf(stateItem) == stateItens.size() - 1) {
        item.setDisabled(true);
        item.setStyleClass("ui-state-disabled");
      }
      stateModel.addElement(item);
    }
  }
  @PostConstruct
  public void init() {
    model = new DefaultMenuModel();

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

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

    model.addElement(firstSubmenu);

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

    item = new DefaultMenuItem("Save");
    item.setIcon("ui-icon-disk");
    item.setCommand("#{menuView.save}");
    item.setUpdate("messages");
    secondSubmenu.addElement(item);

    item = new DefaultMenuItem("Delete");
    item.setIcon("ui-icon-close");
    item.setCommand("#{menuView.delete}");
    item.setAjax(false);
    secondSubmenu.addElement(item);

    item = new DefaultMenuItem("Redirect");
    item.setIcon("ui-icon-search");
    item.setCommand("#{menuView.redirect}");
    secondSubmenu.addElement(item);

    model.addElement(secondSubmenu);
  }
  /**
   * Gera o menu de disciplinas
   *
   * @param disciplinas
   */
  private void criaMenu(List<Disciplina> disciplinas) {
    menuModel = new DefaultMenuModel();

    DefaultSubMenu submenu = new DefaultSubMenu();
    submenu.setLabel("Alunos/Notas");

    DefaultMenuItem item;
    for (Disciplina disciplina : disciplinas) {
      item = new DefaultMenuItem();
      item.setValue(disciplina.getNome());
      item.setCommand("#{professorAcademicoMB.carregarAlunosDisciplinasPorDisciplinaCursando}");
      item.setParam("id", disciplina.getIdDisciplina());
      item.setIcon("ui-icon-extlink");
      submenu.addElement(item);
    }

    getMenuModel().addElement(submenu);
  }
Exemple #4
0
  public MenuModel geraMenu() {
    if (menuModel == null) {
      DefaultSubMenu submenu;

      DefaultMenuItem item;
      menuModel = new DefaultMenuModel();
      submenu = new DefaultSubMenu("Categoria");
      item = new DefaultMenuItem();
      listEst12 = sEst12.listar();
      for (int i = 0; i < listEst12.size(); i++) {
        submenu.addElement(item);
        item = new DefaultMenuItem();
        menuModel.addElement(item);
        submenu.setStyle("font-size : 12px; ");
        item.setValue(listEst12.get(i).getDescricao());
        item.setOutcome(listEst12.get(i).getPath());
        item.setAjax(true);
        item.setCommand("#{mbMenu.produto(" + listEst12.get(i).getIdGrupo() + ")}");
        //                item.setParam("grupoId", 1);
      }
    }
    return menuModel;
  }