简体   繁体   中英

Is there a way to get the fields of a form submitted by workflow in Liferay?

I am working with Liferay 7.2.

I am trying to get the fields of the forms that are sent by notification to the user through a workflow, it is a form created by liferay (Content & Data -> Forms). I have developed the following code:

    import com.liferay.portal.kernel.util.GetterUtil;
    import com.liferay.portal.kernel.workflow.WorkflowConstants;
    import com.liferay.portal.kernel.workflow.WorkflowHandler;
    import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
    import com.liferay.asset.kernel.model.AssetCategory;
    import com.liferay.asset.kernel.model.AssetEntry;
    import com.liferay.asset.kernel.model.AssetRenderer;
    import com.liferay.asset.kernel.model.AssetRendererFactory;
    import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil;
    import com.liferay.dynamic.data.mapping.kernel.DDMForm;

    import java.util.List;

    String className = (String)workflowContext.get(
        WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);

    WorkflowHandler workflowHandler =
        WorkflowHandlerRegistryUtil.getWorkflowHandler(className);

    AssetRendererFactory assetRendererFactory =
        workflowHandler.getAssetRendererFactory();

    long classPK =
        GetterUtil.getLong((String)workflowContext.get
        (WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

    AssetRenderer assetRenderer =
        workflowHandler.getAssetRenderer(classPK);

    AssetEntry assetEntry = assetRendererFactory.getAssetEntry(
        assetRendererFactory.getClassName(), assetRenderer.getClassPK());

    List<AssetCategory> assetCategories = assetEntry.getCategories();
    returnValue = "Default Review";
    System.out.println(assetCategories);
    System.out.println(assetEntry);
    System.out.println(assetRenderer.getAssetObject());
    

Output is, but I do not see where the fields are:

[]

{entryId=56712, groupId=11555, companyId=11552, userId=11561, userName=Test Test, createDate=Tue Dec 15 08:30:19 GMT 2020, modifiedDate=Tue Dec 15 08:30:19 GMT 2020, classNameId=33012, classPK=56708, classUuid=ab012e7a-12387-a7b1-4481-44ab98a6a123, classTypeId=0, listable=true, visible=true, startDate=null, endDate=null, publishDate=null, expirationDate=null, mimeType=text/html, title=Form Record for Form: Send email, description=, summary=, url=, layoutUuid=, height=0, width=0, priority=0.0, viewCount=0}

{mvccVersion=1, uuid=ab012e7a-12387-a7b1-4481-44ab98a6a123, formInstanceRecordId=56708, groupId=11555, companyId=11552, userId=11561, userName=Test Test, versionUserId=11561, versionUserName=Test Test, createDate=Tue Dec 15 08:30:19 GMT 2020, modifiedDate=Tue Dec 15 08:30:19 GMT 2020, formInstanceId=65521, formInstanceVersion=1.46, storageId=40512, version=1.0, lastPublishDate=null}

The form is:

在此处输入图像描述

I think I'm close, but I still can't access the form fields. In this case I want to get the "Email" field. Could you help me? Thanks a lot!

Unfortunately you'll have to dig a bit deeper into the API, but it looks like you're on the right path:

assetRenderer.getAssetObject() reveals an object that looks very much like it's form related, but it won't be a single bean with all the getters and setters you expect: They're unknown at compile-time, thus you'll have to use it to query its attributes.

If you look at assetRenderer.getAssetObject().getClass().getName() , you'll discover what you have at hand, and can dig further based on its interface (and the related APIs for the fields of a form).

I haven't worked with Forms on the code level, so I can't provide the full solution. Maybe someone else does, but until then you have a direction in which to look for one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM