Terry.Li-彬

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
          <2008年3月>
          2425262728291
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(19)

          隨筆分類(107)

          隨筆檔案(141)

          文章分類(284)

          文章檔案(342)

          相冊

          收藏夾(58)

          家裝

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

           

          上回說到/c/portal/render_portlet請求經過MVC過程后會到達render_portlet.jsp。

          render_portlet.jsp
          -------------------------

          Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
          cachePortlet = PortletInstanceFactory.create(portlet, application);
          cachePortlet.render(renderRequestImpl, renderResponseImpl);

          CachePortlet.render()

          _invoke(req, res, false);
          CachePortlet._invoke()
          if (action)
            _portlet.processAction(...)
          else
            _portlet.render(...);

          // 因為87 portlet是一個StrutsPortlet,在這里會調用StrutsPortlet.render()方法,由于StrutsPortlet和 LiferayPortlet中都沒有定義render()方法,最終調用的是GenericPortlet.render()方法。


          GenericPortlet.render()

          response.setTitle(getTitle(request));
          doDispatch(request, response);

          //由于LiferayPortlet中覆蓋了doDispatch()方法,所以調用的是LiferayPortlet.doDispatch()

          LiferayPortlet.doDispatch()

            if (mode.equals(PortletMode.VIEW)) {
              doView(req, res);
            }
            else if (mode.equals(LiferayPortletMode.ABOUT)) {
              doAbout(req, res);
            }
            else if (mode.equals(LiferayPortletMode.CONFIG)) {
              doConfig(req, res);
            }
            .......

          //由于StrutsPortlet中重載了doView, doAbout等方法,所以調用的是StrutsPortlet中的各種doXXX()方法,下面以doView()為例
          // 另外有可能會有別的類型的portlet,例如liferay的JSPPortlet,從而會調用JSPPortlet.doXXX()方法。在 JSPPortlet.doView中,調用include(viewJSP, req, res);而viewJSP = getInitParameter("view-jsp");所以在這個地方就可以把該JSPPortlet定義好的view.jsp直接include 進來,沒有如同StrutsPortlet的后續工作。

          StrutsPortlet.doView()

          include(req, res);

          //StrutsPortlet中其他的doXXX()方法都會最后調用include()方法。

          StrutsPortlet.include()

          PortletRequestProcessor processor = _getPortletRequestProcessor(req);
          processor.process(req, res);
          PortletRequestProcessor.process(RenderRequest req, RenderResponse res)
          //這里PortletRequestProcessor有兩個process方法,一個處理RenderRequest,另一個處理ActionRequest。

          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
          HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(res);

          process(httpReq, httpRes);
          // 由于PortletRequestProcessor和TilesRequestProcessor中都沒有重載process (HttpServletReq, HttpServletRes),調用的是RequestProcessor的process()方法。

          RequestProcessor.process(HttpServletRequest, HttpServletResponse)


          String path = processPath(request, response); //這里是/layout_configuration/view
          ActionMapping mapping = processMapping(request, response, path);
          processForward(request, response, mapping)
          processInclude(request, response, mapping)
          ActionForward forward = processActionPerform(request, response, action, form, mapping);
          ……


          protected void doInclude( String uri, HttpServletRequest request, HttpServletResponse response)
          {
            RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
            rd.include(request, response);
          }

          portlet-custom.xml中定義了:
          <portlet>
            <portlet-name>87</portlet-name>
            <display-name>Layout Configuration</display-name>
              <portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>
              <init-param>
                <name>view-action</name>
                <value>/layout_configuration/view</value>
              </init-param>
              .....
          </portlet>

          struts-config.xml中定義了action:

          <action path="/layout_configuration/view" forward="portlet.layout_configuration.view" />

          tiles-def.xml中定義了view.jsp:

          <definition name="portlet.layout_configuration.view" extends="portlet.layout_configuration"> 
            <put name="portlet_content" value="/portlet/layout_configuration/view.jsp" />
          </definition>

          最后完成了萬里長征,到達了/layout_configuration/view.jsp。

          /layouot_configuration/view.jsp
          -------------------------------------------

              <%
               PortletCategory portletCategory = (PortletCategory)WebAppPool.get(String.valueOf(company.getCompanyId()), WebKeys.PORTLET_CATEGORY);

               List categories = ListUtil.fromCollection(portletCategory.getCategories());

               Collections.sort(categories, new PortletCategoryComparator(company.getCompanyId(), locale));

               Iterator itr = categories.iterator();

               while (itr.hasNext()) {
                request.setAttribute(WebKeys.PORTLET_CATEGORY, itr.next());
               %>

                <liferay-util:include page="/html/portlet/layout_configuration/view_category.jsp" />

               <%
               }
               %>

          /layouot_configuration/view_category.jsp
          -----------------------------------------------------------

          <%
          itr2 = portlets.iterator();

          while (itr2.hasNext()) {
            Portlet portlet = (Portlet)itr2.next();
            divId = new StringMaker();
            divId.append(newCategoryPath);
            divId.append(":");
            matcher = pattern.matcher(PortalUtil.getPortletTitle(portlet, application, locale));
            while (matcher.find()) {
              divId.append(matcher.group());
            }
          %>

          <div class="layout_configuration_portlet" id="<%= divId %>">
            <table border="0" cellpadding="2" cellspacing="0" width="100%">
              <tr>
                <td width="99%">
                  <%= PortalUtil.getPortletTitle(portlet, application, locale) %>
                </td>
                <td align="right">
                  <input type="button" value="<liferay-ui:message key="add" />"
                   onClick="addPortlet('<%= plid%>', '<%= portlet.getPortletId() %>', '<%= themeDisplay.getDoAsUserId() %>');
                   if (<%= !portlet.isInstanceable() %>) {
                    var div = document.getElementById('<%= divId %>');
                    div.parentNode.removeChild(div);
                  };"
           >
                </td>
              </tr>
            </table>
          </div>
          <%
          }
          %>

          在view_category.jsp 中列出了每個category中所包含的portlet列表,一旦點擊了"add"按鈕,會調用addPortlet()方法在頁面上增加一個 portlet。在view_category.jsp中還實現了輸入關鍵字對portlet進行過濾的功能。

           

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

          posted on 2008-03-14 14:12 禮物 閱讀(1206) 評論(0)  編輯  收藏 所屬分類: Liferay
          主站蜘蛛池模板: 靖江市| 尉犁县| 德化县| 岑巩县| 九寨沟县| 吉林市| 汉寿县| 合作市| 方山县| 永城市| 察雅县| 甘泉县| 沙湾县| 汽车| 敦煌市| 武安市| 祁连县| 房产| 亚东县| 鲁山县| 上饶市| 凤山市| 洪雅县| 巴林右旗| 托里县| 偃师市| 香港 | 潜江市| 和静县| 库车县| 徐闻县| 大厂| 台安县| 兴宁市| 景宁| 繁峙县| 都江堰市| 岐山县| 余庆县| 屯门区| 称多县|