為struts-menu的樹(shù)型菜單加入復(fù)選框

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

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

          為struts-menu的樹(shù)型菜單加入復(fù)選框

           

          版本 0.2
            1.
          修改一個(gè)BUG,子菜單錯(cuò)誤的問(wèn)題
            2.
          新增一個(gè)menuId 屬性,用于返回選中的對(duì)像(也就是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 屬性,創(chuàng)建get  / set 方法

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

           

          版本0.1

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

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

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

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

             在類中加入兩個(gè)常數(shù)

             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) 修改以下方法為下面的內(nèi)容

          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的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

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

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

          2007-08-12 15:46 by 困惑
          就是這四點(diǎn)嗎?頁(yè)面內(nèi)容要不要變?

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框[未登錄](méi)  回復(fù)  更多評(píng)論   

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

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

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

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

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

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

          2008-10-31 18:52 by 紙黃金
          一個(gè)字。看得頭暈。。。要慢慢學(xué)

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

          2009-12-01 12:10 by 創(chuàng)意產(chǎn)品批發(fā)
          謝謝!網(wǎng)上找了好久終于找到了。。。

          # re: 為struts-menu的樹(shù)型菜單加入復(fù)選框  回復(fù)  更多評(píng)論   

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

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

          Copyright © oksonic

          主站蜘蛛池模板: 镇坪县| 临城县| 永德县| 常熟市| 莎车县| 华坪县| 三明市| 江山市| 东城区| 乌恰县| 五大连池市| 林周县| 克山县| 威远县| 高陵县| 宁化县| 安庆市| 五华县| 自贡市| 彝良县| 仪陇县| 庆云县| 远安县| 遂溪县| 伊川县| 汤原县| 馆陶县| 新河县| 红原县| 邵东县| 荥阳市| 营口市| 南郑县| 隆安县| 孙吴县| 郁南县| 凯里市| 三河市| 平舆县| 临澧县| 泸定县|