This Is A FineDay

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  93 随笔 :: 0 文章 :: 69 评论 :: 0 Trackbacks
<2006年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(2)

我参与的团队

随笔分类

随笔档案

友情连接

搜索

最新随笔

最新评论

阅读排行榜

评论排行榜

 public ActionForward execute(
   ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response) {
   //创建连接
   Session session=SessionFactory.currentSession();
   //创建事务
   Transaction tx=session.beginTransaction();
   //创建对话
   Query query=session.createQuery("FROM Department");
   List list=query.list();
   //事务提交
   tx.commit();
   if(list.size()<0)
    return mapping.getInputForward();
   MenuRepository repository = new MenuRepository();
   HttpSession httpsession=(HttpSession)request.getSession();
   ServletContext application=(ServletContext)httpsession.getServletContext();
   MenuRepository defaultRepository = (MenuRepository)application.getAttribute(MenuRepository.MENU_REPOSITORY_KEY);
   repository.setDisplayers(defaultRepository.getDisplayers());
    for (int i=0; i < list.size(); i++) {
     MenuComponent mc = new MenuComponent();
     
     Department mi=(Department) list.get(i);
     
     String name = "a" + mi.getDepartmentCode();
             mc.setName(name);
             String parent = "a" + mi.getParentCode();
             System.out.println(name + ", parent is: " + parent);
             if(parent.equals("a0")){
              parent = null;
             }
             if (parent != null) {
                 MenuComponent parentMenu = repository.getMenu(parent);
                 if (parentMenu == null) {
                     System.out.println("parentMenu '" + parent + "' doesn't exist!");
                     // create a temporary parentMenu
                     parentMenu = new MenuComponent();
                     parentMenu.setName(parent);
                     repository.addMenu(parentMenu);
                 }
                 mc.setParent(parentMenu);
             }
             String title = mi.getDepartmentName();
             mc.setTitle(title);
            
          
             mc.setLocation("index.jsp");
             repository.addMenu(mc);
   }
    request.setAttribute("repository", repository);
   return mapping.findForward("okGo");
  }
jsp中
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="/WEB-INF/struts-menu.tld" prefix="menu" %>
<%@ taglib uri="/WEB-INF/struts-menu-el.tld" prefix="menu-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

    <link rel="stylesheet" type="text/css" media="all"
        href="<c:url value="/styles/menuExpandable.css"/>" />
    
     <script type="text/javascript"
        src="<c:url value="/scripts/menuExpandable.js"/>"></script>
    <link rel="stylesheet" type="text/css" media="all"
        href="<c:url value="/styles/xtree.css"/>" />
    <script type="text/javascript"
        src="<c:url value="/scripts/xtree.js"/>"></script>
       
    <link rel="stylesheet" type="text/css" media="screen"
        href="<c:url value="/styles/global.css"/>" />
       
       
    <script type="text/javascript">
        /* Function for showing and hiding elements that use 'display:none' to hide */
        function toggleDisplay(targetId) {
            if (document.getElementById) {
                target = document.getElementById(targetId);
                if (target.style.display == "none"){
                    target.style.display = "";
                } else {
                    target.style.display = "none";
                }
            }
        }
    </script>
   <!--
    <div class="dynamicMenu tree">
        <menu:useMenuDisplayer name="ListMenu" repository="repository">
            <menu:displayMenu name="a01"/>
            <menu:displayMenu name="a02"/>
        </menu:useMenuDisplayer>
    </div>
   
    <div class="dynamicMenu tree">
    <script type="text/javascript">
        <menu:useMenuDisplayer name="Velocity" config="/templates/xtree.html"
            repository="repository">
          <c:forEach var="menu" items="${repository.topMenus}">
            <menu-el:displayMenu name="${menu.name}"/>
          </c:forEach>
        </menu:useMenuDisplayer>
    </script>
    </div>
    -->
 <div id="content">
 <script type="text/javascript" src="<c:url value="/scripts/coolmenus3.js"/>"></script>
 <script type="text/javascript" src="<c:url value="/scripts/coolmenu-config.js"/>"></script>
        <menu:useMenuDisplayer name="CoolMenu"  repository="repository">
            <menu:displayMenu name="a01"/>
            <menu:displayMenu name="a02"/>
        </menu:useMenuDisplayer>
    </div>
menu-config.xml
<?xml version="1.0" encoding="UTF-8" ?>

<MenuConfig>

  <Displayers>
    <Displayer   name="DropDown"
                 type="net.sf.navigator.displayer.DropDownMenuDisplayer"/>
    <Displayer   name="Simple"
                 type="net.sf.navigator.displayer.SimpleMenuDisplayer"/>
    <Displayer   name="CoolMenu"
                 type="net.sf.navigator.displayer.CoolMenuDisplayer"/>
    <Displayer   name="CoolMenu4"
                 type="net.sf.navigator.displayer.CoolMenuDisplayer4"/>
    <Displayer   name="MenuForm"
                 type="net.sf.navigator.example.PermissionsFormMenuDisplayer"/>
    <Displayer   name="ListMenu"
                 type="net.sf.navigator.displayer.ListMenuDisplayer"/>
    <Displayer   name="TabbedMenu"
                 type="net.sf.navigator.displayer.TabbedMenuDisplayer"/>
    <Displayer   name="Velocity"
                 type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>
  </Displayers>

  <Menus>
 
  </Menus>

</MenuConfig>

posted on 2006-10-24 16:56 Peter Pan 阅读(610) 评论(0)  编辑  收藏 所属分类: SSH

只有注册用户登录后才能发表评论。


网站导航: