cancel
Showing results for 
Search instead for 
Did you mean: 

Form Processor not able to generate form

les21
Champ in-the-making
Champ in-the-making

Hi,

I'm trying to display a custom form using Alfresco.util.PopupManager.displayForm() however I'm having an issue trying to use my own form processor. It works without a hitch if I use the itemKind: "type", so the type processor but if I try to use my own "adduser" processor it just shows a blank form.

Alfresco.util.PopupManager.displayForm(
    {
        title: "Select Users",
        properties:
        {
            mode: "create",
            itemKind: "adduser",
            itemId: "scwf:adduser",
            showCancelButton: "false"
        },
        success:
        {
            fn: function()
            {
                // do something if successful
            },
            scope: this
        },
        successMessage: "Update of node " + workflowid + " was successful.",
        failure:
        {
            fn: function()
            {
                // do something if failure
            },
            scope: this
        },
        failureMessage: "Update of node " + workflowid + " failed."
    });

The form is defined in xml and I know that my processor is correctly registering because I can see log messages in the console, here is my generate() code in the form processor.

public Form generate(Item item, List<String> fields, List<String> forcedFields, Map<String,Object> context){
     item.setType("type");
     //we are going to fool it into thinking it's generating a type form, then switch the url under it
     //Form f = super.generate(item, fields, forcedFields, context);
     Form f = new Form(item);
     Item formItem = f.getItem();
        formItem.setType("scwf:adduser");
        formItem.setUrl("/api/classes/scwf_adduser");
     
     logger.debug(f);
     Object itemData = makeItemData(item);
        FormCreationData data = new FormCreationDataImpl(itemData, forcedFields, context);
        populateForm(f, fields, data);
        logger.debug(f);
        FormData de = new FormData();
        de.addFieldData("assoc_scwf_assignees", "");
        f.addField(new PersonField(KEY1_FORM_FIELD, "Attribute key1 - mandatory", "Key1", true));
        f.setFormData(de);
        f.setSubmissionUrl("/share/sidn/workflows/");
        logger.debug("Ye: " + f.getItem());
        logger.debug(f);
       return f;   
    }
protected Object makeItemData(Item item) {
        // Return the attribute item with optionally the value set
        return item;
    }

This code is suppose to be generating a form that looks like the xml definition:

<config evaluator="string-compare" condition="scwf:adduser">
  <forms>
   <form>
    <field-visibility>
     <show id="scwf:assignees" force="true" />
    </field-visibility>
    <appearance>
     <set id="" appearance="title" label-id="workflow.set.general" />
     <set id="items" label="Document" />
     <set id="other" label="Review Outcome" />
     <set id="assignee" label-id="workflow.set.assignees" />
     <set id="response" label-id="workflow.set.response" />
     
     <field id="scwf:assignees" label-id="workflow.field.reviewers" set="assignee">
         <control template="/org/alfresco/components/form/controls/authority3.ftl">
       <control-param name="compactMode">false</control-param>
       <control-param name="forceEditable">false</control-param>
      </control>
     </field>
    </appearance>
   </form>
  </forms>
 </config>

So in other words it just needs to contain one field, the authority.ftl field (in this case I modified it via form control). What am I doing wrong?

1 REPLY 1

les21
Champ in-the-making
Champ in-the-making

Solved this by doing the following:

Error was "please provide a namespace resolver" when using super.generate(). This is because in the code for the superclass it references the null value this.namespace. 

I did not solve that issue and rather did a work around, I copied a lot of the code from the default form processor (stuff like getTypeItem(), generateDefaultFields(), makeItemData()...) and changed stuff as needed. The real key for me was that I needed to use fieldProcessorRegistry.buildField(fieldName, data); in order to use the xml file as a field definition. 

After adding that and also for some reason needing to set

Item formItem = f.getItem();
formItem.setType("scwf:adduser");
formItem.setUrl("/api/classes/scwf_adduser");

 

Everything works as intended and I can safely override the default submit url to do my own parsing of the form results.