如何在 alfresco 中向页面添加表单

how to add a form to a page in alfresco

我在 share-config-custom.xml 配置文件中定义了表单,并且我有一个 home.ftl 页面。如何将配置文件中的表单定义与 home.ftl 页面相关联?

您可以使用 content-type 打开共享表单 打开表单

function render(htmlPageId) {
var contentType = "content_type";
    var formHtmlId = htmlPageId+ "-metadata-form";
    var url = YAHOO.lang
            .substitute(
                    "{serviceContext}components/form"
                            + "?itemKind=type&itemId={itemId}&mode=create&submitType=json"
                            + "&formId={formId}&showCancelButton=true&htmlid={htmlid}"
                            + "&destination={destination}&siteId={siteId}&containerId={containerId}&uploadDirectory={uploadDirectory}",
                    {
                        serviceContext : Alfresco.constants.URL_SERVICECONTEXT,
                        itemId : contentType,
                        itemKind : "model",
                        formId : "upload-folder",
                        destination : "workspace://SpacesStore/e9d60c89-823a-4e3e-abb2-522e59a09d0f",
                        siteId : "production",
                        containerId : "documentLibrary",
                        uploadDirectory : "/GM",
                        htmlid : formHtmlId
                    });

    Alfresco.util.Ajax.request({
        url : url,
        responseContentType : "html",
        execScripts : true,
        successCallback : {
            fn : function(response) {
                var formNode = YAHOO.util.Dom.get(formHtmlId);
                formNode.innerHTML = response.serverResponse.responseText;

            },
            scope : this
        },
        failureCallback : {
            fn : function(response) {
                Alfresco.logger.debug("onContentTypeChange failureCallback",
                        arguments);
            },
            scope : this
        }
    });
}

在此处传递您的内容类型 - contentType 您想要打开的表单类型。

var formNode = YAHOO.util.Dom.get(formHtmlId);
 formNode.innerHTML = response.serverResponse.responseText;

formHtmlId 是您的 html 组件的 ID 喜欢

<div id="${el}-renderForm" onload="render(htmlID)">
</div>

在此函数中传递您当前的 htmlId。

您可以通过 /components/form 网络脚本检索配置的表单,因此您可以使用 javascript 控制器将您的表单注入您的页面,如@vikash 先前的回答中所述,或者您可以使用Spring 浏览以创建页面,为此您可以检查 Alfresco documentation Surf Pages

在定义页面中,将/components/form设为url,将url参数设为属性,如下例

<?xml version="1.0" encoding="UTF-8"?>
<component>
    <url>/components/form</url>
     <properties>
        <itemKind>type</itemKind>
        <itemId>contentType</itemId>
        <mode>edit</mode>
        <formUI>true</formUI>
        <submitType>json</submitType>
        <showCaption>true</showCaption>
        <showCancelButton>true</showCancelButton>
     </properties>
</component>

如果你想获得配置类型的表格,你应该在 itemKind 中制作 type 并在 itemId 中键入名称 (cm:xxx)