`

Richfaces tree 通过读取property文件构建树

阅读更多

view:

 <h:panelGrid columns="1" width="100%">  
   <rich:tree style="width:100px" nodeSelectListener="#{simpleTreeBean.processSelection}"
    reRender="selectedNode" ajaxSubmitSelection="true"  switchType="client"
    value="#{simpleTreeBean.treeNode}" var="item">
   </rich:tree>   
    <h:outputText escape="false" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" />
  </h:panelGrid>

 

 

bean:

 

public class RichTreeBean {
 private TreeNode rootNode = null;
 
 private String nodeTitle;
 
 private static final String DATA_PATH = "/WEB-INF/classes/simple-tree-data.properties";
 
 private void addNodes(String path, TreeNode node, Properties properties) {
  boolean end = false;
  int counter = 1;
  
  while (!end) {
   String key = path != null ? path + '.' + counter : String.valueOf(counter);

   String value = properties.getProperty(key);
   if (value != null) {
    TreeNodeImpl nodeImpl = new TreeNodeImpl();
    nodeImpl.setData(value);
    node.addChild(new Integer(counter), nodeImpl);
    
    addNodes(key, nodeImpl, properties);
    
    counter++;
   } else {
    end = true;
   }
  }
 }
 
 private void loadTree() {
  FacesContext facesContext = FacesContext.getCurrentInstance();
  ExternalContext externalContext = facesContext.getExternalContext();
  InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH);
  try {
   Properties properties = new Properties();
   properties.load(dataStream);
   
   rootNode = new TreeNodeImpl();
   addNodes(null, rootNode, properties);
   
  } catch (IOException e) {
   throw new FacesException(e.getMessage(), e);
  } finally {
   if (dataStream != null) {
    try {
     dataStream.close();
    } catch (IOException e) {
     externalContext.log(e.getMessage(), e);
    }
   }
  }
 }
 
 public TreeNode getTreeNode() {
  if (rootNode == null) {
   loadTree();
  }
  
  return rootNode;
 }

 public void processSelection(NodeSelectedEvent event) {
  UITree tree = (UITree) event.getComponent();
  nodeTitle = (String) tree.getRowData();
 }
 
 public String getNodeTitle() {
  return nodeTitle;
 }

 public void setNodeTitle(String nodeTitle) {
  this.nodeTitle = nodeTitle;
 }}

 

 

 

property文件:

 

1=Daniel Defo
1.1=Robinson Crusoe
1.1.1=Start In Life
1.1.2=Slavery And Escape
1.1.3=Wrecked On A Desert Island
1.1.4=First Weeks On The Island
1.1.5=Builds A House - The Journal
1.1.6=Ill And Conscience-Stricken
1.1.7=Agricultural Experience
1.1.8=Surveys His Position
1.1.9=A Boat
1.1.10=Tames Goats
1.1.11=Finds Print Of Man's Foot On The Sand
1.1.12=A Cave Retreat
1.1.13=Wreck Of A Spanish Ship
1.1.14=A Dream Realised
1.1.15=Friday's Education
1.1.16=Rescue Of Prisoners From Cannibals
1.1.17=Visit Of Mutineers
1.1.18=The Ship Recovered
1.1.19=Return To England
1.1.20=Fight Between Friday And A Bear
2=Edgar Allan Poe
2.1=Plays
2.1.1=Politian
2.2=Short stories
2.2.1=The Assignation
2.2.2=Berenice
2.2.3=The Black Cat
2.2.4=The Cask of Amontillado
2.2.5=A Descent into the Maelstrom
2.3=Poetry
2.3.1=Alone
2.3.2=An Enigma
2.3.3=Annabel Lee
2.3.4=Bridal Ballad
3=Henry Wadsworth Longfellow
3.1=The Song of Hiawatha
3.1.1=Introduction
3.1.2=I. The Peace-Pipe
3.1.3=II. The Four Winds
3.1.4=III. Hiawatha's Childhood
3.1.5=IV. Hiawatha and Mudjekeewis
3.1.6=V. Hiawatha's Fasting
3.1.7=VI. Hiawatha's Friends
3.1.8=VII. Hiawatha's Sailing
3.1.9=VIII. Hiawatha's Fishing
3.1.10=IX. Hiawatha and the Pearl-Feather
3.1.11=X. Hiawatha's Wooing
3.1.12=XI. Hiawatha's Wedding-Feast
3.1.13=XII. The Son of the Evening Star
3.1.14=XIII. Blessing the Cornfields
3.1.15=XIV. Picture-Writing
3.1.16=XV. Hiawatha's Lamentation
3.1.17=XVI. Pau-Puk-Keewis
3.1.18=XVII. The Hunting of Pau-Puk-Keewis
3.1.19=XVIII. The Death of Kwasind
3.1.20=XIX. The Ghosts
3.1.21=XX. The Famine
3.1.22=XXI. The White Man's Foot
3.1.23=XXII. Hiawatha's Departure
3.2=Poetry
3.2.1=A Psalm Of Life
3.2.2=Birds Of Passage
3.2.3=Hiawatha's Childhood
3.2.4=Hymn To The Night

 

 

分享到:
评论

相关推荐

    richfaces tree权限树

    "richfaces tree权限树"是一个基于RichFaces框架构建的用于实现权限管理的树形结构组件。RichFaces是一个功能强大的JavaServer Faces(JSF)扩展库,它提供了许多高级UI组件和Ajax功能,使得开发人员能够更轻松地...

    RichFaces自动构建树实现(中文)

    其中,`&lt;t:tree&gt;` 组件是RichFaces中用于构建树形结构的高级UI元素,支持多种事件监听和AJAX交互。 ##### 2. **树形结构的自动生成** 在RichFaces中,树形结构的自动生成主要依赖于数据模型和组件配置。开发者首先...

    JSF Richfaces构建树

    ### JSF Richfaces构建树知识点解析 #### 一、树形结构基础概念 在软件开发领域,树形结构是一种常用的数据结构,具有多种应用场景。树形结构由一系列节点组成,每个节点可以拥有零个或多个子节点。在树形结构中,...

    richfaces自动构建树实现.docx

    RichFaces 提供了树形结构接口和默认的实现类,我们可以通过使用默认的实现类来构建树,也可以实现它的接口来自定义一个树。 在 OECP 系统中,无可避免的存在着大量的属性结构,最典型的就是组织结构,这些树形结构...

    使用richfaces 实现tree

    在Java世界中,JSF(JavaServer Faces)是一种用于构建用户界面的服务器端MVC框架,而RichFaces是它的一个扩展库,...通过熟练掌握`&lt;rich:tree&gt;`组件,我们可以创建出功能丰富、交互性强的树形视图,满足各种业务需求。

    richfaces 相关资料2

    6. **RichFaces自动构建树实现.pdf** - 类似于前面的文档,这个PDF文件可能提供了更详细的步骤或示例,指导读者如何使用RichFaces自动构建树结构。 **总结** RichFaces是一个流行的JavaServer Faces (JSF)组件库,...

    richfaces-ui-3.2.1

    这通常包含所有必要的JAR文件,用于构建和运行RichFaces 3.2.1的应用。这些库包含了RichFaces的组件库、AJAX引擎、以及其他依赖的库,如JSF API和实现、以及可能的第三方库。开发者在项目中引用这些JARs,就可以在...

    最简单的richfaces tree使用方式

    NULL 博文链接:https://yourenyouyu2008.iteye.com/blog/798333

    richfaces tree 例子

    按照richfaceslivedemo中的例子 改成节点存储在数据库中 把数据库生成好 添加数据 就可以用了 数据库脚本:if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[node]') and OBJECTPROPERTY(id,...

    用richFaces的<rich:treeNode>标签开发tree

    总的来说,`&lt;rich:treeNode&gt;`标签是RichFaces框架中构建动态树形视图的强大工具,它提供了丰富的功能和高度的灵活性,使得开发者能够轻松地构建复杂的数据层次结构,提高Web应用程序的用户交互性和可操作性。...

    Richfaces ShowCase离线包

    **Richfaces ShowCase离线包** 是一个专为开发者设计的资源包,它包含了Richfaces框架的演示示例,能够帮助用户在没有网络连接的情况下也能深入理解和学习Richfaces的功能和用法。这个离线包特别适合那些需要在本地...

    richfaces tree 案例

    @Out(required=false,scope=SESSION) private TreeNode rootNode = null; private List&lt;String&gt; selectedNodeChildren = new ArrayList(); private String nodeTitle; private static final String DATA_PATH...

    richfaces参考文档

    - **&lt;rich:tree&gt;**:创建可扩展的树形视图,支持拖放操作和节点状态管理。 - ****:增强版的树组件,支持拖放操作,常用于构建可配置的树状结构。 ### RichFaces 集成与配置 - **Maven 依赖**:在 Maven 项目中,...

    richfaces(里面包含JAR包)

    6. **集成与配置**:在Eclipse中,开发者需要将RichFaces的JAR包添加到项目的构建路径中,然后在web.xml文件中配置JSF和RichFaces的上下文参数和监听器。 7. **AJAX支持**:RichFaces通过Ajax4jsf库提供了AJAX功能...

    richfaces4.0所需jar包

    总结来说,这个压缩包提供的JAR文件是构建和运行基于RichFaces 4.0的应用程序所必需的依赖。它们涵盖了从组件实现、CSS处理到框架核心功能的各个方面,确保了富客户端功能的顺利运行和高效性能。在实际开发中,将...

    richfaces3.2用户手册的pdf版

    3. **集成到Maven项目**:对于使用Maven 构建工具的项目,可以通过POM 文件轻松地引入RichFaces 的依赖。 #### 四、不同环境下的设置 - **Web 应用程序描述符参数**:针对不同的部署环境,需要调整 web.xml 文件中...

    richfaces-3.0.0

    这个压缩包可能包含了构建脚本、示例应用、测试用例和其他辅助文件,帮助开发者更好地理解和使用 RichFaces。 **详细知识点:** 1. **JavaServer Faces (JSF):** JSF 是一个基于组件的服务器端 Web 应用程序开发...

    richfaces-ui-3.3.GA jar

    6. **集成到项目**:开发人员可以通过将 "richfaces-ui-3.3.GA.jar" 添加到项目的类路径中,利用 RichFaces 的功能来构建更复杂的用户界面,例如使用其预定义的组件(如表格、数据网格、对话框等)。 7. **开发与...

    Richfaces组件使用指南

    总的来说,RichFaces为开发者提供了一个强大的工具集,用于构建具有丰富交互性和动态性的JSF应用,大大简化了开发过程,提高了开发效率,同时也增强了用户体验。通过其内置的Ajax支持、组件库、资源管理和皮肤机制,...

Global site tag (gtag.js) - Google Analytics