What's JAVA ?

          發現在我走近java之后,感覺自己什么都不會了!
          posts - 13, comments - 7, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          tree2小試

          Posted on 2006-01-05 21:34 Eddie Lee 閱讀(10990) 評論(1)  編輯  收藏 所屬分類: JSF
          tree2是Myfaces的tomahawk控件中的一個,在使用tomahawk控件之前一定先確定已經按照myfaces的要求配置好web.xml文件。
          Myfaces網站tomahawk欄目的Extensions Filter 子欄目中有如下一段話:
          If you just use standard JSF component, but don't use any MyFaces' extended component (beginning with t:),
          then you don't need the Extensions Filter.
          However, if you use some of the MyFaces' extended components like t:inputFileUpload, t:inputHTtml, t:inputCalendar, ...
          then you most likely need to have this filter configured in your webapp.
          大概意思是,如果你在項目中沒有使用到Myfaces的擴展組件(t:開頭的),則你不需要配置這個Filter.
          可是,如果你用了Myfaces的擴展組件,你必須為你的web程序配置這個Filter.
          配置如下:
          <filter>
              
          <filter-name>MyFacesExtensionsFilter</filter-name>
              
          <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
              
          <init-param>
                  
          <param-name>maxFileSize</param-name>
                  
          <param-value>20m</param-value>
                  
          <description>Set the size limit for uploaded files.
                      Format: 10 - 10 bytes
                              10k - 10 KB
                              10m - 10 MB
                              1g - 1 GB
                  
          </description>
              
          </init-param>
          </filter>

          <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages  -->
          <filter-mapping>
              
          <filter-name>MyFacesExtensionsFilter</filter-name>
              
          <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
              
          <servlet-name>Faces Servlet</servlet-name>
          </filter-mapping>

          <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.)  -->
          <filter-mapping>
              
          <filter-name>MyFacesExtensionsFilter</filter-name>
              
          <url-pattern>/faces/myFacesExtensionResource/*</ url-pattern>
          </filter-mapping>

          要使用MyFaces的tomahawk控件,要在頁面引用<%@ taglib uri="在頁面中添加tree2的標簽:

          <t:tree2 id="sortTree" var="node" varNodeToggler="t" showRootNode="false" value="#{tree.treeData}">

          </t:tree2>
          建立托管Bean,用于填充tree。
          public class TreeBacker implements Serializable
          {
              
          public TreeNode getTreeData ( )
              
          {
                  TreeNode treeData 
          = new TreeNodeBase ( "foo-folder" , "Inbox" , false ) ;

                  TreeNodeBase personNode 
          = new TreeNodeBase("person""Eddie L"false);
                  
          //personNode.getChildren().add(new TreeNodeBase("document","Eddie doc one", true));
                  TreeNodeBase doc = new TreeNodeBase("document","Eddie doc one"true);
                  doc.setIdentifier(
          "No.1");
                  personNode.getChildren().add(doc);
                  treeData.getChildren().add(personNode);
                  
                  System.out.println ( 
          "Create Tree ..ok" ) ;
                  
          return treeData ;
              }

          }

          其中TreeNodeBase personNode = new TreeNodeBase("person", "Eddie L", false);中的"person"的作用是表示渲染得時候顯示什么樣式,
          跟頁面中<f:facet name="person"></f:facet>相對應。
          在頁面中

          <f:facet name="person">
              
          <h:panelGroup>
                  
          <f:facet name="expand">
                      
          <t:graphicImage value="../images/person.png" rendered="#{t.nodeExpanded}" border="0" />
                  
          </f:facet>
                  
          <f:facet name="collapse">
                      
          <t:graphicImage value="../images/person.png" rendered="#{!t.nodeExpanded}" border="0" />
                  
          </f:facet>
                  
          <h:outputText value="#{node.description}" styleClass="nodeFolder" />
              
          </h:panelGroup>
          </f:facet>

          <t:graphicImage value="../images/person.png" rendered="#{t.nodeExpanded}" border="0" />顯示Tree每一個節點的圖片。rendered屬性的意思是是否渲染的意思,
          jsf中渲染的意思是把jsf組件樹當前的狀態轉換成html。在jsf的生命周期里,渲染響應在最后一個周期,rendered值為false在渲染相應這個周期就不運行。
          在處理葉子節點上,需要特殊的注意。因為對葉子節點是需要操作的。可能需要點擊葉子節點連接到一個頁面,或者執行某些action等。
          <f:facet name="document">
              
          <h:panelGroup>
                  
          <h:commandLink immediate="true" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}" actionListener="#{t.setNodeSelected}" action="#{tree.okListener}" id="clickbutton">
                      
          <t:graphicImage value="../images/document.png" border="0" />
                      
          <h:outputText value="#{node.description}" />
                      
          <f:param name="docNum" value="#{node.identifier}" />
                  
          </h:commandLink>
              
          </h:panelGroup>
          </f:facet>
          commandLink標記可以有n個參數,參數分為參數名和參數值。在程序里可以讀取。
          編寫action事件:okListener
          FacesContext context = FacesContext.getCurrentInstance ( ) ;//取得上下文

          String a 
          = context.getExternalContext ( ).getRequestParameterMap ( )
                          .get ( 
          "docNum" ).toString ( ) ;

          a的值就是docNum的值。
          identifier的值在創建樹的時候一起加進去的:
          TreeNodeBase doc = new TreeNodeBase("document","Eddie doc one", true);
          doc.setIdentifier("No.1");

          這樣。一個tree2的應用基本就算ok了。


          評論

          # re: tree2小試  回復  更多評論   

          2006-08-02 15:07 by zhongweiqi
          很簡潔,很使用,能不能再詳細一點,說一下怎么才能得到點擊葉子結點的事件,如果能舉一個小例子就好了,
          謝謝!!!!
          主站蜘蛛池模板: 绿春县| 卢湾区| 仁布县| 洛宁县| 凭祥市| 厦门市| 镇康县| 梁河县| 玉林市| 巫山县| 鄂托克前旗| 灌阳县| 叙永县| 龙岩市| 北川| 白水县| 孟津县| 襄垣县| 三亚市| 石家庄市| 吉木萨尔县| 岳普湖县| 安阳市| 镇巴县| 张北县| 新安县| 马关县| 青河县| 时尚| 武汉市| 德江县| 崇义县| 湘阴县| 安宁市| 昭觉县| 汉源县| 宜宾市| 平阳县| 普兰店市| 巴林右旗| 高雄市|