Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學;靜其心,可悟天下之理;恒其心,可成天下之業。

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
           

          談了這么多,還沒說怎么自己往Liferay中創建和加入一個portlet,Liferay中定義了幾種類型的portlet,如JSPPortlet,StrutsPortlet,和VelocityPortlet。先以JSPPortlet為例說明吧。

          1. 定義新的JSP Portlet

          a) 首先到 ...\portlet\ext中去加入自己要創建的portlet文件夾,例如myappletportlet,在文件夾中創建一個view.jsp,其中的內容可最簡單為:

          Hello JSPPortlet world!

          最好的起始學習方法應該是照葫蘆畫瓢吧,找一個已有的portlet,看它的結構和代碼。

          b) 到 ...\WEB-INF\portlet-ext.xml 中加入
          <portlet>
           <portlet-name>EXT_2</portlet-name>
           <!-- portlet 的最關鍵ID -->

           <display-name>My AppletPortlet</display-name>

           <portlet-class>com.liferay.portlet.JSPPortlet</portlet-class>
           <!-- portlet 所屬的類 -->

           <init-param>
            <name>view-jsp</name>
            <value>/portlet/ext/myappletportlet/view.jsp</value>
            <!-- MVC中會直接傳遞到view.jsp -->
           </init-param>
           <expiration-cache>300</expiration-cache>
           <supports>
            <mime-type>text/html</mime-type>
           </supports>
           <portlet-info>
            <title>PENG Portlet</title>
            <!-- Portlet上顯示的名字 -->
           </portlet-info>
           <security-role-ref>
            <role-name>Power User</role-name>
           </security-role-ref>
           <security-role-ref>
            <role-name>User</role-name>
           </security-role-ref>
          </portlet>

          c) 到 ...\WEB-INF\liferay-portlet-ext.xml 中加入

          <portlet>
           <portlet-name>EXT_2</portlet-name>
          </portlet>

          d) 到...\WEB-INF\liferay-display.xml 中加入以下代碼,以將EXT_2加入sample分類,到時候在Add Content時可以在這個sample組找到,否則在undefined中找。

          <category name="category.sample">
           <portlet id="47"/>
           ......
           <portlet id="EXT_2"/>
          </category>

          e) 測試。如果上述的修改是直接在tomcat目錄中進行的話,重新啟動tomcat。如果是在前面提到的自己創建的EXT環境下進行的話,先用ant一下,再啟動tomcat。然后http://localhost:8080/,用test@liferay.com/test進去,選擇Add Content,應該可以在sample目錄下找到前面創建的那個portlet了:PENG Portlet。


          2. 定義新的StrutsPortlet。過程要略微復雜一些,誰叫我們要用傳說中的MVC呢。先列出幾個關鍵的配置文件:
          portlet-ext.xml: 定義portlet(JSR-168 attributes)
          liferay-portlet-ext.xml: 注冊portlet(Liferay attributes)
          struts-config.xml: 定義 page-flow (action mapping)
          tiles-defs.xml: 定義 the page layout
          更詳細的信息可從Liferay的官方網站上獲得。

          a) 在ext中增加一個叫做Tiles的portlet文件夾,在其中創建一個view.jsp。內容可以簡單為:

          Hello StrutsPortlet world!

          b) Portlet-ext.xml 中加入
          <portlet>
           <portlet-name>EXT_3</portlet-name>
           <display-name>Tiles</display-name>
           <portlet-class>
            com.liferay.portlet.StrutsPortlet
            <!—實現JSR-168規范的類 -->
           </portlet-class>

           <init-param>
            <name>view-action</name>
            <value>/ext/tiles/view</value>
             <!-- portal會到struts-config.xml中去尋找/ext/tiles/view -->
           </init-param>
           <expiration-cache>0</expiration-cache>
           <supports>
            <mime-type>text/html</mime-type>
           </supports>
           <resource-bundle>
            com.liferay.portlet.StrutsResourceBundle
           </resource-bundle>
           <security-role-ref>
            <role-name>user</role-name>
           </security-role-ref>
          </portlet>


          c) liferay-portlet-ext.xml中加入

          <portlet>
           <portlet-name>EXT_3</portlet-name>
           <struts-path>ext/tiles</struts-path>
           <!-- 告訴portal所有帶有ext/tiles/*路徑的請求可以認為是這個portlet的范圍 -->
           <use-default-template>false</use-default-template>
           <!-- 因為將采用別的template,所以設置為false。將要使用的template在tiles-defs.xml中定義。-->
          </portlet>


          d) struts-config-ext.xml中加入

          <action path="/ext/tiles/view"
           forward="portlet.ext.tiles.view" />
          <!-- Struts 將會在 tiles-defs.xml 中尋找 portlet.ext.tiles.view -->

          e) 在tiles-defs-ext.xml 中加入

          <definition name="portlet.ext.tiles.view" extends="portlet">
          <!-- 定義了哪個 template 將被使用,這里是portlet template。這個template 定義了portlet的borders和buttons(例如minimize, maximize, close 等等)。 -->

          <put name="portlet_content" value="/portlet/ext/tiles/view.jsp" />
           <!-- portlet_content 是一個liferay的變量,portal可以使用這個變量來決定在portlet中會呈現什么內容。這里portlet的內容就是view.jsp。 -->
          </definition>

          f) 測試。

           

          Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2177436

          posted on 2008-03-14 14:15 禮物 閱讀(1547) 評論(2)  編輯  收藏 所屬分類: Liferay

          評論

          # re: 深入淺出Liferay Portal (12) 2009-03-30 14:59 小雨
          你好,
          寫得很好,受益匪淺,在下有兩個問題,請仁兄賜教:
          1. 本人想在 theme vm 中使用 iframe 讓portal 內容部分 布局成左右兩邊,結果頁面無法顯示,該如何處理?

          2.目前 portal內容/菜單都是同時刷新,是否可以實現 僅內容頁面刷新,菜單/頭部不刷新?
          比如portal:/web/guest/aa 如果在portal_normal.vm中使用iframe a, a.src = "/web/guest/aa", 這樣的話整個頁面都加到了 a中,如何實現只加載portal 內容部分

          謝謝!   回復  更多評論
            

          # re: 深入淺出Liferay Portal (12) 2009-09-28 11:37 liferay
          歡迎加群49588979一起討論學習liferay  回復  更多評論
            

          主站蜘蛛池模板: 通道| 荣成市| 宜宾县| 舒城县| 通化县| 五莲县| 门源| 武夷山市| 离岛区| 滨州市| 临漳县| 福清市| 新密市| 景谷| 松江区| 徐水县| 石河子市| 抚顺市| 建昌县| 河北区| 鄂尔多斯市| 垣曲县| 武宁县| 房产| 长阳| 新竹县| 离岛区| 瑞金市| 濉溪县| 苗栗县| 临清市| 蒲城县| 平原县| 攀枝花市| 邓州市| 嵩明县| 嘉荫县| 阳信县| 获嘉县| 田东县| 九龙县|