將AEM Forms工作區元件整合至網頁應用程式 integrating-aem-forms-workspace-components-in-web-applications

CAUTION
AEM 6.4已結束延伸支援,本檔案不再更新。 如需詳細資訊,請參閱 技術支援期. 尋找支援的版本 此處.

您可以使用AEM Forms工作區 元件 在您自己的Web應用程式中。 下列範例實作使用CRX™例項上安裝之AEM Forms工作區開發套件中的元件來建立Web應用程式。 根據您的特定需求自訂下列解決方案。 範例實作會重新使用 UserInfo, FilterList,和 TaskList網站入口網站內的元件。

  1. 登入CRXDE Lite環境,位置為 https://[server]:[port]/lc/crx/de/. 確認已安裝AEM Forms Workpace開發套件。

  2. 建立路徑 /apps/sampleApplication/wscomponents.

  3. 複製css、影像、js/libs、js/runtime和js/registry.js

    • /libs/ws
    • /apps/sampleApplication/wscomponents.
  4. 在/apps/sampleApplication/wscomponents/js資料夾內建立demomain.js檔案。 將程式碼從/libs/ws/js/main.js複製至demomain.js。

  5. 在demomain.js中,移除要初始化Router的程式碼,並新增下列程式碼:

    code language-none
    require(['initializer','runtime/util/usersession'],
        function(initializer, UserSession) {
            UserSession.initialize(
                function() {
                    // Render all the global components
                    initializer.initGlobal();
                });
        });
    
  6. 按名稱在/content下建立節點 sampleApplication 和類型 nt:unstructured. 在此節點的屬性中,添加 sling:resourceType 類型字串和值 sampleApplication. 在此節點的「訪問控制清單」中,為 PERM_WORKSPACE_USER 允許jcr:read權限。 此外,在 /apps/sampleApplicationPERM_WORKSPACE_USER 允許jcr:read權限。

  7. /apps/sampleApplication/wscomponents/js/registry.js 更新路徑 /lc/libs/ws/ to /lc/apps/sampleApplication/wscomponents/ ,以了解範本值。

  8. 在門戶首頁JSP檔案中,位於 /apps/sampleApplication/GET.jsp,請新增下列程式碼,將必要的元件納入入口網站中。

    code language-as3
    <script data-main="/lc/apps/sampleApplication/wscomponents/js/demomain" src="/lc/apps/sampleApplication/wscomponents/js/libs/require/require.js"></script>
    <div class="UserInfoView gcomponent" data-name="userinfo"></div>
    <div class="filterListView gcomponent" data-name="filterlist"></div>
    <div class="taskListView gcomponent" data-name="tasklist"></div>
    

    也包含AEM Forms工作區元件所需的CSS檔案。

    note note
    NOTE
    呈現時,每個元件都會新增至元件標籤(具有類別元件)。 請確定您的首頁包含這些標籤。 請參閱 html.jsp 檔案,進一步了解這些基本控制項標籤。
  9. 要自定義元件,可以按如下方式擴展所需元件的現有視圖:

    code language-as3
    define([
        ‘jquery’,
        ‘underscore’,
        ‘backbone’,
        ‘runtime/views/userinfo'],
        function($, _, Backbone, UserInfo){
            var demoUserInfo = UserInfo.extend({
                //override the functions to customize the functionality
                render: function() {
                    UserInfo.prototype.render.call(this); // call the render function of the super class
                    …
                    //other tasks
                    …
                }
            });
            return demoUserInfo;
    });
    
  10. 修改入口網站CSS,以設定入口網站上所需元件的版面、定位和樣式。 例如,您想要讓此入口網站的背景顏色保持黑色,以便順利檢視userInfo元件。 您可以在 /apps/sampleApplication/wscomponents/css/style.css 如下所示:

    code language-as3
    body {
        font-family: "Myriad pro", Arial;
        background: #000;    //This was origianlly #CCC
        position: relative;
        margin: 0 auto;
    }
    
recommendation-more-help
a6ebf046-2b8b-4543-bd46-42a0d77792da