寧?kù)o以思遠(yuǎn)

          Java使人內(nèi)心寧?kù)o

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            8 Posts :: 0 Stories :: 17 Comments :: 0 Trackbacks

          2009年12月10日 #

          以前在公司,平臺(tái)組已經(jīng)把組件都給我們開(kāi)發(fā)好了,對(duì)于界面沒(méi)有花太多的時(shí)間研究。近日想自己做個(gè)小系統(tǒng),還是用比較擅長(zhǎng)的JSF+Hibernate+Spring。考慮Facelet的模板功能,這次想嘗試一下。結(jié)果,一個(gè)Tree2就把我納悶了好一會(huì)。
          從網(wǎng)上找了篇文章,試著依樣畫葫蘆,做了模板頁(yè),分top,left,content三塊布局,left自然就是tree2菜單了。
          首先看一下模板頁(yè):
          template.xthml
          1 <div id="left">
          2          <ui:insert name="left">
          3                     <ui:include src="leftmenu.xhtml"></ui:include>
          4          </ui:insert>
          5 </div>
          6 <div id="content" class="left_content">
          7          <ui:insert name="content">Content</ui:insert>
          8 </div>
          其中左邊菜單:
          leftmenu.xhtml
           1 <t:tree2 id="serverTree" value="#{calendarBean.treeData}" var="node" varNodeToggler="t" clientSideToggle="false" showRootNode="true">
           2                            
           3                             <f:facet name="document">
           4                                 <h:panelGroup>
           5                                     <h:commandLink immediate="true" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}" action="link_page" actionListener="#{t.setNodeSelected}">
           6                                         <t:graphicImage value="/images/document.png" border="0"/>
           7                                         <h:outputText value="#{node.description}"/>
           8                                         <f:param name="docNum" value="#{node.identifier}"/>
           9                                     </h:commandLink>
          10                                 </h:panelGroup>
          11                             </f:facet>
          12  </t:tree2>
          其中backingBean代碼如下,配置有效范圍為session
          public class calendarBean {

              
          private TreeData treeData;

              
          private Date secondDate;

              
          public Date getSecondDate() {
                  
          return secondDate;
              }

              
          public void setSecondDate(Date secondDate) {
                  
          this.secondDate = secondDate;
              }

              
          public TreeData getTreeDate() {
                 
          if (null == treeData) {
                      TreeNode treeData 
          = new TreeNodeBase("foo-folder""Inbox"false);
                      ......
                 }
                 
          return treeData;
          }
          ......
          }

          這里為了方便測(cè)試,故意把commandLink的action指向link_page導(dǎo)航,link_page配置為:
          1 <navigation-rule>
          2     <from-view-id>/treeSample2.xhtml</from-view-id>
          3     <navigation-case>
          4         <from-outcome>link_page</from-outcome>
          5       <to-view-id>/treeSample2link.xhtml</to-view-id>
          6     </navigation-case>
          7   </navigation-rule>
          treeSample2.xhtml和treeSample2link.xhtml分別為兩個(gè)使用了template.xhtml模板的頁(yè)面,顯然它們都用到了菜單。

           運(yùn)行后,首先打開(kāi)treeSample.xhtml,非常成功,菜單出來(lái)了,而且由于使用了Server端樹,每次打開(kāi)子節(jié)點(diǎn),都會(huì)提交到服務(wù)器,頁(yè)面刷新后,除了正在操作的節(jié)點(diǎn),其他節(jié)點(diǎn)也都保持原來(lái)的狀態(tài)。

          但是,當(dāng)我點(diǎn)擊節(jié)點(diǎn),跳轉(zhuǎn)到treeSample2link.xhtml時(shí),問(wèn)題出來(lái),所有節(jié)點(diǎn)都折疊起來(lái),而并沒(méi)有保持我原來(lái)頁(yè)面的狀態(tài)。這說(shuō)明從一個(gè)頁(yè)面跳轉(zhuǎn)到另一個(gè)頁(yè)面時(shí),節(jié)點(diǎn)狀態(tài)并沒(méi)有被傳遞過(guò)去。
          有些想不明白,既然backingbean是session的,為什么沒(méi)有記錄節(jié)點(diǎn)的狀態(tài)呢?網(wǎng)上搜了些資料,很少有提到關(guān)于狀態(tài)的。myface的wiki中似乎也找不到類似的問(wèn)題。無(wú)奈之下,只能直接看tree2的代碼,終于發(fā)現(xiàn)了問(wèn)題所在。原來(lái)我有個(gè)TreeState接口存儲(chǔ)節(jié)點(diǎn)狀態(tài)的,而它又是被set到treeModel的,而我的代碼中只使用了treeData,沒(méi)有給它包裝成treeModel。Tree2中提供了treeModel的一個(gè)實(shí)現(xiàn)treeModelBase,直接使用就可以了。于是乎,改一下代碼:
           1 public class calendarBean {
           2   
           3       private TreeModel personTreeModel;
           4   
           5       public TreeModel getPersonTreeModel() {
           6           if (null == personTreeModel) {
           7               TreeNode treeData = new TreeNodeBase("foo-folder""Inbox"false);
           8                  
           9               personTreeModel = new TreeModelBase(treeData);
          10           }
          11         return personTreeModel;
          12     }
          13  
          14 }
          改一下綁定:
          1  <t:tree2 id="serverTree" value="#{calendarBean.persontreeModel}" 
          測(cè)試一下,果然,無(wú)論怎么鏈接,依然保持良好的狀態(tài),呵呵。
          posted @ 2009-12-10 00:02 Aaronbamoo 閱讀(1310) | 評(píng)論 (4)編輯 收藏

          2009年12月9日 #

          上次發(fā)博還是07年9月的事,那時(shí)我還在運(yùn)營(yíng)商,這時(shí)自己私下再學(xué)Java,偶爾上來(lái)寫點(diǎn)心得。沒(méi)想過(guò)了幾個(gè)星期,我轉(zhuǎn)身離開(kāi)運(yùn)營(yíng)商,來(lái)到了設(shè)備商做研發(fā),終于如愿能做些自己喜歡做的工作了,但是忙碌的工作之余,卻忘記了再來(lái)寫點(diǎn)什么。而兩年不到的時(shí)間,我又再次回到了另一個(gè)運(yùn)營(yíng)商,發(fā)現(xiàn)還是放不下在研發(fā)的日子,又開(kāi)始想做點(diǎn)什么。于是乎,又開(kāi)始想寫點(diǎn)什么。這好比一個(gè)輪回,其中的得失,只有自己明白。
          posted @ 2009-12-09 23:16 Aaronbamoo 閱讀(152) | 評(píng)論 (0)編輯 收藏

          2007年9月5日 #

          /home/aaron/Desktop/Screenshot.png
          posted @ 2007-09-05 22:16 Aaronbamoo 閱讀(394) | 評(píng)論 (0)編輯 收藏

          2007年7月16日 #

          1,ArrayList的Generics
          public class ArrayListGenericDemo 
            
          public static void main(String[] args) 
              ArrayList
          <String> data = new ArrayList<String>(); 
              data.add(
          "hello"); 
              data.add(
          "goodbye"); 
              
          // data.add(new Date()); This won't compile! 
              Iterator<String> it = data.iterator(); 
              
          while (it.hasNext()) 
                String s 
          = it.next(); 
                System.out.println(s); 
              }
           
            }
           
          }
           
          2,HashMap的Generics
          public class ArrayListGenericDemo 
            
          public static void main(String[] args) 
              ArrayList
          <String> data = new ArrayList<String>(); 
              data.add(
          "hello"); 
              data.add(
          "goodbye"); 
              
          // data.add(new Date()); This won't compile! 
              Iterator<String> it = data.iterator(); 
              
          while (it.hasNext()) 
                String s 
          = it.next(); 
                System.out.println(s); 
              }
           
            }
           
          }
           
          posted @ 2007-07-16 11:07 Aaronbamoo 閱讀(190) | 評(píng)論 (0)編輯 收藏

          2007年5月23日 #

                 盡管EJB2.0自出生就帶來(lái)了很多非議,但是<head first EJB>仍然值得拜讀,原本一直被外界的評(píng)論所影響,不敢碰關(guān)于EJB的東西,剛剛在CSDN上學(xué)習(xí)了前幾章,發(fā)現(xiàn)原來(lái)EJB雖然有些復(fù)雜,但是也不是高不可攀。今天正好把第三章看完,明天就有朋友幫我把書帶來(lái)了,繼續(xù)奮斗!
                 盡管過(guò)多的不相關(guān)工作延緩了Java的學(xué)習(xí)進(jìn)程,但是只要堅(jiān)持信仰,不斷努力,一定會(huì)看到希望!
          posted @ 2007-05-23 18:08 Aaronbamoo 閱讀(416) | 評(píng)論 (4)編輯 收藏

          2007年3月25日 #

          ??? 最近在寫Hibernate+struts的程序,發(fā)現(xiàn)為了完成一個(gè)查詢功能,廢的勁還真不少,總感覺(jué)很不爽。真不知道它好在哪里,繼續(xù)學(xué)習(xí)<深入淺出Hibernate>。

          posted @ 2007-03-25 22:40 Aaronbamoo 閱讀(240) | 評(píng)論 (0)編輯 收藏

          2007年3月21日 #

               摘要: [IBM developerWorks 中國(guó) ?] 本文講述了如何利用Java的反射的機(jī)制來(lái)簡(jiǎn)化Structs應(yīng)用程序的開(kāi)發(fā)。 Struts中引入ActionForm類的意義與缺陷: 在Struts應(yīng)用程序中,ActionForm是一個(gè)很重要的概念,它的主要功能就是為Action的操作提供與客戶表單...  閱讀全文
          posted @ 2007-03-21 10:05 Aaronbamoo 閱讀(210) | 評(píng)論 (1)編輯 收藏

          2007年3月20日 #

          ??? 快速學(xué)習(xí)了一遍《head first servlet/jsp》,發(fā)現(xiàn)再次去回顧struts的核心技術(shù),變得那么容易理解。昨天再一次調(diào)試開(kāi)發(fā)struts實(shí)例,寫完后一次性運(yùn)行成功,哈哈,盡管很簡(jiǎn)單的程序,還是很爽!
          ??? 今天把validation框架又加入到struts,再次運(yùn)行成功,不過(guò)化了不少時(shí)間調(diào)試,一個(gè)很低級(jí)的錯(cuò)誤,action的配置中忘了加屬性validate="true",怪不得總是沒(méi)有驗(yàn)證就直接轉(zhuǎn)發(fā)。希望朋友們別犯同樣的錯(cuò)誤,呵呵!
          ??? 在西安已經(jīng)呆了快半個(gè)月了,有點(diǎn)喜歡上這個(gè)城市,相比南方城市的柔美,這里多了幾分人文的大氣。很喜歡和這里的人們交談,帶著陜西口音的普通話總是很耐聽(tīng);很喜歡這里的飲食,不需要化太多的錢,就能吃上地道的西安小吃;很喜歡這里的街道,直來(lái)直往,永遠(yuǎn)都不會(huì)迷路。不斷挖掘西安的文明,將是上課之余一件令人興奮的事。
          posted @ 2007-03-20 16:47 Aaronbamoo 閱讀(1201) | 評(píng)論 (8)編輯 收藏

          僅列出標(biāo)題  
          主站蜘蛛池模板: 淮北市| 出国| 罗田县| 阿荣旗| 宝鸡市| 永福县| 寻甸| 托克逊县| 陆丰市| 富川| 开化县| 昌邑市| 太康县| 镇康县| 噶尔县| 西畴县| 简阳市| 桃园市| 万州区| 马山县| 长汀县| 新疆| 手机| 伊宁县| 微山县| 张家港市| 和田市| 江油市| 搜索| 伊川县| 门源| 灌阳县| 河西区| 黄浦区| 长顺县| 林芝县| 镇原县| 佛学| 三都| 阳城县| 长岛县|