Custom handlers types

formdef.xsd

  <xs:element name="myhandler">
    <xs:complexType>
      <xs:annotation>
        <xs:appinfo>
          <forms:formhandler
            tid="module.forms.myhandler"
            descriptiontid="module.forms.myhandlerdesc"
            handlerobject="../../lib/internal/forms/myhandler.whlib#myhandler"
            editfragment="/screens/forms/myhandler.xml#settings"
            />
        </xs:appinfo>
      </xs:annotation>
    </xs:complexType>
  </xs:element>


myhandler.xml

  <fragment name="settings">
    <contents>
      <textedit name="data" />
    </contents>
  </fragment>

myhandler.whlib

The settings fragment should derive from FormComponentBase and implement LoadData and StoreData.

The handler XML node is passed as 'this->node' to the FormComponentBase

PUBLIC OBJECTTYPE Settings EXTEND FormComponentBase
<
  UPDATE PUBLIC MACRO LoadData()
  {
    this->data->value := this->node->GetAttribute("data");
  }

  UPDATE PUBLIC MACRO StoreData()
  {
    this->node->SetAttribute("data", this->data->value);
  }
>;

You should use a 'managedtask' for processing form results wherever possible, as this reduces the chances for form submissions to fail due to errors in your task handling. Managedtasks are also easier to restart/debug than  online processing.

To link up a form handler to a managed task, add a handlertask attribute to its <formhandler> node in the formdef.xsd, set up a managedtask in the moduledefinition, and make sure your implementation derives from FormHandlerTaskBase (not ManagedTaskBase or FormHandlerBase)

PUBLIC OBJECTTYPE MailResultsTask EXTEND FormHandlerTaskBase
<
  UPDATE PUBLIC MACRO RunFormTask(RECORD results)
  {
    /* Add code. 
       this->settings contains the attributes applied to your form node
       when done, this->ResolveByCompletion
    */
  }
>;

Last but not least, you may need to add a <formhandler> to your form's apply rule (or to a <to type="all"> rule)

PreviousNext

Comments