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

Posted on 2007-07-20 19:18 oksonic 閱讀(6753) 評論(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 - 35, comments - 1104, trackbacks - 0, articles - 0

Copyright © oksonic

湖北快3号码表 体彩甘肃11选5与哪个省一样 股票涨停的规定 北京11选5技巧大全 pc蛋蛋赔率跟踪 今快3开奖结果查询 十分快三大小单双的玩法 融资炒股是什么意思 江苏快3基本二码遗漏 理财平台排名2017 足彩混合投注