為struts-menu的樹型菜單加入復選框

          Posted on 2007-07-20 19:18 oksonic 閱讀(7007) 評論(8)  編輯  收藏 所屬分類: java

          下載全部源代碼:http://www.oksonic.cn

          為struts-menu的樹型菜單加入復選框

           

          版本 0.2
            1.
          修改一個BUG,子菜單錯誤的問題
            2.
          新增一個menuId 屬性,用于返回選中的對像(也就是checkBoxvalue值)

           

          修改部份:CheckListMenuDisplayer.java

              原:

                   protected void displayComponents(MenuComponent menu, int level)

              throws JspException, IOException {

                  MenuComponent[] components = menu.getMenuComponents();

                if(menu.isChecked())

                  checked = CHECKBOX_IS_CHECKED;

                  else

                  checked = CHECKBOX_ISNOT_CHECKED;

                  if (components.length > 0) {

                 紅字部份取消,移到以下位置:

              for (int i = 0; i < components.length; i++) {

                        MenuComponent mMenu = components[i];

                        if(menu.isChecked())

                           checked = CHECKBOX_IS_CHECKED.replaceFirst("\\?", mMenu.getMenuId());

                          else

                            checked = CHECKBOX_ISNOT_CHECKED.replaceFirst("\\?", mMenu.getMenuId());

                          // check the permissions on this component

                          if (isAllowed(components[i])) {

                 …………

              MenuBase中加入 String menuId 屬性,創建get  / set 方法

          **************************************************************************************

           

          版本0.1

          1. 修改net.sf.navigator.menu.MenuBase 類,加入checked屬性,生成get/set方法

          2. 修改net.sf.navigator.displayer.DisplayerStrings.properties資源文件,在帶有<li標簽的結束符后面加入{4}

             如:lmd.menu.top=\t<li class="menubar">{4}\n

          3. 新建net.sf.navigator.displayer.CheckListMenuDisplayer.java文件,此文件的內容為ListMenuDisplayer.java加以修改而成

             在類中加入兩個常數

             private static final String CHECKBOX_IS_CHECKED="<input type='checkbox' name='checked' checked='CHECKED'/>";

             private static final String CHECKBOX_ISNOT_CHECKED="<input type='checkbox' name='checked'/>";

             /** 用于判斷是否選中 **/

              private String checked = CHECKBOX_ISNOT_CHECKED;

           

             a) 修改以下方法為下面的內容

          public void display(MenuComponent menu) throws JspException, IOException {

                  if (isAllowed(menu)) {

                      if(menu.isChecked())

                  checked = CHECKBOX_IS_CHECKED;

                     else

                  checked = CHECKBOX_ISNOT_CHECKED;

                      out.println(displayStrings.getMessage("lmd.menu.top", null,null,null,null,checked));

                      displayComponents(menu, 0);

                      out.println(displayStrings.getMessage("lmd.menu.bottom"));

                  }

              }

           

           

              protected void displayComponents(MenuComponent menu, int level)

              throws JspException, IOException {

                  MenuComponent[] components = menu.getMenuComponents();

                if(menu.isChecked())

                  checked = CHECKBOX_IS_CHECKED;

                  else

                  checked = CHECKBOX_ISNOT_CHECKED;

                  if (components.length > 0) {

                      // eliminate spaces in string used for Id

                      String domId = StringUtils.deleteWhitespace(getMessage(menu.getName()));

                      // added to create a unique id everytime

                      domId += ((int) (1000*Math.random()));

           

                      String menuClass = "menu";

           

                      if (level >= 1) {

                          menuClass = "submenu";

                      }

           

                      // if there is a location/page/action tag on base item use it

                      if (menu.getUrl() != null ){

                          out.println(displayStrings.getMessage("lmd.menu.actuator.link",

                                      domId, getMessage(menu.getTitle()), menuClass,

                                      getMessage(menu.getUrl())));

                      } else {

                          out.println(displayStrings.getMessage("lmd.menu.actuator.top",

                                  domId,

                                  getMessage(menu.getTitle()),

                                  menuClass));

                      }

                     

                      for (int i = 0; i < components.length; i++) {

                          // check the permissions on this component

                          if (isAllowed(components[i])) {

                              if (components[i].getMenuComponents().length > 0) {

                                  out.println("<li>");

                                  displayComponents(components[i], level + 1);

           

                                  out.println(displayStrings.getMessage("lmd.menu.actuator.bottom"));

                              } else {

                                  out.println(displayStrings.getMessage("lmd.menu.item",

                                                                        components[i].getUrl(),

                                                                        super.getMenuToolTip(components[i]),

                                                                        getExtra(components[i]),

                                                                        this.getMessage(components[i].getTitle()),

                                                                        checked

                                                                        ));

                              }

                          }

                      }

           

                      // close the </ul> for the top menu

                      if (menuClass.equals("menu")) {

                          out.println("</ul>");

                      }

                  } else {

                      if (menu.getParent() == null) {

                          out.println(displayStrings.getMessage("lmd.menu.standalone",

                                                                menu.getUrl(),

                                                                super.getMenuToolTip(menu),

                                                                getExtra(menu),

                                                                getMessage(menu.getTitle()),checked));

                      } else {

                          out.println(displayStrings.getMessage("lmd.menu.item",

                                                                menu.getUrl(),

                                                                super.getMenuToolTip(menu),

                                                                getExtra(menu),

                                                                getMessage(menu.getTitle()), checked));

                      }

                  }

              }

           

           

          4. 修改樣式文件

          @import url(global.css);

           

          .menuList {

            margin: 0px;

            padding: 10px 0px 10px 15px;

          }

           

          li.menubar {

            background: url(../images/plus.gif) no-repeat 2.2em 0.5em;

            font-size: 12px;

            line-height: 1.5em;

            list-style: none outside;

          }

           

          .menu, .submenu {

            display: none;

            margin-left: 15px;

            padding: 0px;

          }

           

          .menu li, .submenu li  {

            background: url(../images/square.gif) no-repeat 2em 0.5em;

            list-style: none outside;

          }

           

          li.menubar a.standalone {

            background: url(../images/square.gif) no-repeat 2em 0.5em !important;

          }

           

          a.actuator, a.standalone {

            background-color: transparent;

            color: #000;

            font-size: 12px;

            padding-left: 15px;

            text-decoration: none;

          }

           

           

          .menu li a, .submenu li a {

            background-color: transparent;

            color: #000;

            font-size: 12px;

            padding-left: 15px;

            text-decoration: none;

          }

           

          a.actuator:hover, .menu li a:hover, submenu li a:hover, li a.standalone:hover {

            text-decoration: underline;

          }

           

          /* styles to allow for base links */

          li a.base, li a.base:visited {

            background-color: transparent;

            color: #000;

            font-size: 12px;

            padding-left: 0px;

            text-decoration: none;

          }

           

          li a.base:hover {

            color: #CC0000;

            text-decoration: none;

          }

           

          span.key {

            text-decoration: underline;

          }

           

          a.highlight {

              color: red !important;

              font-weight: bold;

          }

           

           

           

          email:oksonic@tom.com

          Feedback

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2007-08-11 08:32 by banseon
          最近你的文章越寫越少啦.是不是太忙了.

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2007-08-12 15:46 by 困惑
          就是這四點嗎?頁面內容要不要變?

          # re: 為struts-menu的樹型菜單加入復選框[未登錄]  回復  更多評論   

          2007-11-28 20:46 by dd
          能否告知一下jsp頁面的情況阿?

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2008-03-12 23:20 by 紙黃金
          好像很忙哦不見你寫文章了

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2008-05-22 16:58 by 百度Hi
          很棒,樓主很忙吶!~~~非常感謝。

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2008-10-31 18:52 by 紙黃金
          一個字。看得頭暈。。。要慢慢學

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2009-12-01 12:10 by 創意產品批發
          謝謝!網上找了好久終于找到了。。。

          # re: 為struts-menu的樹型菜單加入復選框  回復  更多評論   

          2010-04-16 17:16 by 北京翻譯公司
          哈哈

          posts - 103, comments - 1104, trackbacks - 0, articles - 0

          Copyright © oksonic

          主站蜘蛛池模板: 宁海县| 邻水| 墨脱县| 崇明县| 山东省| 盘山县| 惠东县| 兴安盟| 乐清市| 东至县| 炎陵县| 普安县| 防城港市| 峨眉山市| 昔阳县| 潼南县| 奉节县| 南华县| 高州市| 海安县| 泰来县| 龙陵县| 榕江县| 兴城市| 丹凤县| 嫩江县| 施秉县| 抚顺市| 平湖市| 娄底市| 邢台县| 漳平市| 古浪县| 高邮市| 安仁县| 南川市| 八宿县| 玉门市| 定西市| 元朗区| 屏边|