Class HeadlessForms

java.lang.Object
com.axelor.meta.headless.HeadlessForms

@Singleton public class HeadlessForms extends Object
Runs forms on the server, with no browser: the entry point of headless forms.

A session opens a FormSpec on a Target — a new record or a saved one — and runs steps on it; every chain they reach runs as the web client runs it, in the context of the record it acts on.


 FormSession form = forms.open(FormSpec.of("sale.orders"), Target.record(id));
 FormResult result = form.run(List.of(FormStep.set("confirmed", true), FormStep.save()),
     ActionInteraction.CANCEL_ALL);
 

Transactions. Each server round trip runs as the browser's request does: a save or a read in a transaction of its own, an action chain in none, each action keeping its own. A caller that holds a transaction is joined instead. So outside a transaction a save before a later stop stays saved, as in a browser; inside one the session is atomic, and the caller rolls back on anything but FormResult.Status.DONE.

Permissions are the current user's, checked by the server entry points as for a browser.

  • Method Details

    • open

      public FormSession open(FormSpec spec, Target target)
      Opens a form on a record. For a spec of an action-view, the action-view is evaluated as a menu opens it, and its context joins every action's.
      Throws:
      IllegalArgumentException - when the action-view opens nothing, or a custom model's form is opened on a record of another custom model
    • restore

      public FormSession restore(FormState state)
      A session again from its state, where it stopped; the spec is built anew.