-
FEATURED COMPONENTS
First time here? Check out the FAQ!
package com.zion.controllers; import java.awt.BorderLayout; import java.sql.*; import java.util.*; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Sessions; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.*; import com.zion.masters.*; import java.util.ArrayList; import org.zkoss.zk.ui.Executions; /** * * @author LD000754 */ public class SessionController extends GenericForwardComposer { public String Login, Name, EmployeeID, Active; public Menubar mainMenu; private BorderLayout menubar; public List ls = new java.util.ArrayList(); private org.zkoss.zul.Include bodyLayout; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); this.MenuCreate(); } public void MenuCreate() throws SQLException { boolean valid = Sessions.getCurrent().getAttribute("EmployeeID") != null ? true : false; if (!valid) { //nameDisplay.setLabel(""); //Executions.sendRedirect("ErrorHandler.zul"); } else { Login = Sessions.getCurrent().getAttribute("Login").toString(); Name = Sessions.getCurrent().getAttribute("Name").toString(); EmployeeID = Sessions.getCurrent().getAttribute("EmployeeID").toString(); Active = Sessions.getCurrent().getAttribute("Active").toString(); Menu homeMenu = new Menu(); homeMenu.setParent(mainMenu); homeMenu.setLabel("Home"); homeMenu.setImage("/images/toolbar/Home.gif"); homeMenu.setId("Home"); homeMenu.addEventListener("onClick", new MyListener()); CheckSession_AcessMenu checksession = new CheckSession_AcessMenu(); String accessGroupid = checksession.AccessGroupid(EmployeeID); if (accessGroupid.length() > 0) { List rootModules = new ArrayList(); rootModules = checksession.getRootModule(EmployeeID); Iterator itrootModules = rootModules.iterator(); Sessions.getCurrent().setAttribute("AccessGroupID", accessGroupid); while (itrootModules.hasNext()) { EmployeeAccess empAccess = (EmployeeAccess) itrootModules.next(); String rootModuleID = empAccess.getModuleid(); String rootModuleNameS = empAccess.getModuleName(); Menu rootMenu = new Menu(); rootMenu.setParent(mainMenu); rootMenu.setLabel(rootModuleNameS); Menupopup popupAdmin = new Menupopup(); popupAdmin.setParent(rootMenu); menuCreation(rootModuleID, popupAdmin); } } Menu nameDisplay = new Menu(); Menupopup popupName = new Menupopup(); Menuitem itemName = new Menuitem(); itemName.setLabel("Logout"); itemName.setParent(popupName); itemName.setId("Logout"); itemName.addEventListener("onClick", new MyListener()); popupName.setParent(nameDisplay); nameDisplay.setParent(mainMenu); nameDisplay.setImage("/images/toolbar/tvResource.gif"); String setLable = Name + " ( " + Login + " )"; nameDisplay.setLabel(setLable); } } public void menuCreation(String rootModuleID, Menupopup popup) throws SQLException { CheckSession_AcessMenu checksession = new CheckSession_AcessMenu(); List childList = new ArrayList(); childList = checksession.getChildModule(rootModuleID, EmployeeID); Iterator itChild = childList.iterator(); while (itChild.hasNext()) { EmployeeAccess employeeAccess = (EmployeeAccess) itChild.next(); String Moduleid = employeeAccess.getModuleid(); String Modulename = employeeAccess.getModuleName(); String URL = employeeAccess.getSubModuleURL(); List childListInn = new ArrayList(); childListInn = checksession.getChildModule(Moduleid, EmployeeID); Menuitem itemModule1 = new Menuitem(); if (childListInn.size() == 0) { itemModule1.setLabel(Modulename); itemModule1.setParent(popup); itemModule1.setId(Moduleid); itemModule1.setAttribute("URL", URL); itemModule1.addEventListener("onClick", new MyListener()); } else if (childListInn.size() > 0) { Menupopup childPopup = new Menupopup(); Menu childMenu = new Menu(); childMenu.setLabel(Modulename); childPopup.setParent(childMenu); childMenu.setParent(popup); menuCreation(Moduleid, childPopup); } } } class MyListener implements org.zkoss.zk.ui.event.EventListener { public void onEvent(org.zkoss.zk.ui.event.Event event) { try { String controlID = event.getTarget().getId(); if (controlID.equalsIgnoreCase("Logout") || controlID.equalsIgnoreCase("Home")) { if (controlID.equalsIgnoreCase("Logout")) { Sessions.getCurrent().invalidate(); Executions.sendRedirect("index.zul"); } if (controlID.equalsIgnoreCase("Home")) { bodyLayout.setSrc("home.zul"); } } else { CheckSession_AcessMenu checksession = new CheckSession_AcessMenu(); boolean valid = Sessions.getCurrent().getAttribute("EmployeeID") != null ? true : false; if (valid) { String URL = checksession.GetModuleURL(controlID).toString(); if (URL != null) { bodyLayout.setSrc(URL); } } else { Executions.sendRedirect("index.zul"); } } } catch (Exception ex) { } } } }
Does this code works? I have a difficulties with such menu generation..
Hi good afternoon, I also see I have the same problem when displaying menu options dynamically. sime can help thank you very much,
package com.zion.controllers;
import java.awt.BorderLayout; <-- ???????????????????????
import java.sql.*;
. . .
good afternoon, from time to investigate and consult on the internet I found that you must declare to the file. zul the menu as follows
<menubar id="imsmenu" width="800px" apply="com.drishti.Admin.MenuCreation ">
</menubar>
and the class should not be
public class extends MenuCreation GenericAutowireComposer
but
public class extends MenuCreation GenericForwardComposer
Asked: 2010-08-26 06:26:57 +0800
Seen: 1,570 times
Last updated: Aug 10 '12