JSF控件实现动态加载树状菜单

 

使用JSF中的<ig:Sidebar></ig:Sidebar>实现动态加载菜单,其中bar.getChildren().add(aSidebarGroup);是实现动态加载首节点,HtmlSidebarGroup aSidebarGroup = (HtmlSidebarGroup) application.createComponent(HtmlSidebarGroup.COMPONENT_TYPE);
    aSidebarGroup.setText(boardName);
    aSidebarGroup.setExpanded(true);
    aSidebarGroup.setId(viewRoot.createUniqueId());实现加载该节点下的子节点,非常方便。

private Sidebar buildSideBar(Sidebar bar)
 {
  boolean isInitialised = bar.getAttributes().get("IS_INITIALISED")!=null;
  
  if (!isInitialised) {
   // Get a reference to the JSF Application,
   // we need it to create value bindings later-on
   Application application = FacesContext.getCurrentInstance().getApplication();
   UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
   
   /* Create Infragistics SidebarGroup */
   // Set the Sidebar's width and height
   bar.getAttributes().put("style","width: 155px; height: 590px;");
   // Create SidebarGroup
   List list = this.getBoardNameForMenu();
   for(int i = 0 ;i<list.size();i++)
   {
    Object[] row = (Object[])list.get(i);
   //Object[] row = (Object[])list.listIterator().next();
    String boardId = String.valueOf(row[0]);
    String boardName = String.valueOf(row[1]);
    String parentId = String.valueOf(row[2]);
    HtmlSidebarGroup aSidebarGroup = (HtmlSidebarGroup) application.createComponent(HtmlSidebarGroup.COMPONENT_TYPE);
    aSidebarGroup.setText(boardName);
    aSidebarGroup.setExpanded(true);
    aSidebarGroup.setId(viewRoot.createUniqueId());
   
    // Add the newly created SidebarGroup to the Sidebar's children list
    bar.getChildren().add(aSidebarGroup);
    
    List ls = this.getBoardNameForMenuBar(Integer.parseInt(boardId));
    if(ls.size() != 0)
    {
     for(int j=0;j<ls.size();j++)
     {
      Object[] row1 = (Object[])ls.get(j);
      String boardid = String.valueOf(row1[0]);
      String boardname = String.valueOf(row1[1]);
      //HtmlSidebarGroup aSidebarGroup = (HtmlSidebarGroup) application.createComponent(HtmlSidebarGroup.COMPONENT_TYPE);
      HtmlLink aLink1 = (HtmlLink)application.createComponent(HtmlLink.COMPONENT_TYPE);
      aLink1.setId(viewRoot.createUniqueId());
      //aSidebarGroup.setText(sidebarGroupNameStr);
      //aSidebarGroup.setExpanded(true);
      //aSidebarGroup.setId(viewRoot.createUniqueId());
      //aLink1.setId(parentId);
      aLink1.setUrl("/pages/bbs/visitor/topic/topicforboard.jsf?boardid="+boardid+"");
      aLink1.setValue(boardname);
      aSidebarGroup.getChildren().add(aLink1);
     }
    }
    
   }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值