为struts-menu的树型菜单加入复选框

Posted on 2007-07-20 19:18 oksonic 阅读(6989) 评论(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