JSF动态生成菜单
2011-08-16 19:57
375 查看
使用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);
}
}
}
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);
}
}
}
相关文章推荐
- 根据表中数据动态生成菜单(三)
- 右键菜单功能动态生成子项
- 使用dtree生成的树结构,ajax动态加载子节点后,如何绑定右键菜单续
- Vs2005的win form动态生成菜单 (转)
- OpenCMS动态生成导航菜单
- 动态生成javascript树形菜单
- [留着备用]ASP.NET动态菜单生成通用方法
- 【转载】【权限控制】角色访问动态生成用户权限菜单树(转载: http://www.comprg.com.cn/post_show.asp?id=7873 )
- C/S模式根据权限基于反射机制实现动态生成菜单
- extjs desktop 菜单动态生成
- Flash+XML生成动态导航菜单代码
- 层叠菜单的动态生成
- 动态生成静态菜单
- vb.net winform动态生成菜单(源码)
- c#使用Dataset读取XML文件动态生成菜单的方法
- WinForm动态生成菜单
- PB中实现菜单的动态生成(函数递归实现)
- VC++中动态生成菜单技巧
- DevExpress动态生成菜单、子菜单
- c#从数据库读取数据动态生成树形菜单