Class FormSpec

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

public final class FormSpec extends Object
What a session needs to know about a form, compiled from views once and cached: the model, its hooks, fields and buttons, the fields a record is read with, the limits of running it without a browser, and, for each one-to-many, the spec of a line there — a line is a form too.

A spec is built from an action-view (of(String)), a form view (of(Class, String)) or a model alone (of(Class): no hooks, no buttons — defaults, set, save). Where each part comes from is the web client's rule, applied to the definitions; the user's personalized views are ignored. Building a spec is the only place that reads views: a session and a validator of stored steps work on the same spec.

  • Method Details

    • of

      public static FormSpec of(String actionView)
      The spec of an action-view's form: its form view by name, else the model's default form. The action-view is read as defined, not evaluated: a session evaluates it when it opens, for the context every action carries.
      Throws:
      IllegalArgumentException - when the action is not an action-view with a model, or it has no form
    • of

      public static FormSpec of(Class<? extends Model> model, String formView)
      The spec of a form view of a model; no action-view context.
      Parameters:
      formView - the form's name, or null for the model's default form
      Throws:
      IllegalArgumentException - when there is no such form
    • of

      public static FormSpec of(Class<? extends Model> model)
      The spec of a model alone: its fields, no hooks, no buttons; its lines as the default form of their model gives them. For an import that wants the server's save rules and nothing else.
    • model

      public Class<? extends Model> model()
    • jsonModel

      public String jsonModel()
      The custom model, for a custom model's form; null otherwise.
    • actionView

      public String actionView()
      The action-view the spec was built from, or null.
    • formName

      public String formName()
      The name of the form view the spec was compiled from, or null when it has none.
    • definition

      public FormView definition()
      The form view the spec was compiled from — extensions merged, view processors applied — or null for a model alone and for a line edited inline. For readers of what the spec does not model. It is a view of its own, looked up apart from the one the spec reads its widgets and lines from, so nothing a reader does with it changes what a session does.
    • onNew

      public String onNew()
    • onLoad

      public String onLoad()
    • onSave

      public String onSave()
    • fields

      public Map<String,FormSpec.Field> fields()
      The fields, by the name a step writes them by.
    • buttons

      public Map<String,FormSpec.Button> buttons()
      The buttons and menu items, by name.
    • readFields

      public Set<String> readFields()
      The fields a record of this form is read with, as the client asks for them.
    • readRelated

      public Map<String,List<String>> readRelated()
      The sub-fields read for each collection the form shows.
    • limits

      public List<FormLimit> limits()
      What a browser would do with this form that a session does not.
    • line

      public FormSpec line(String collection)
      The spec of a line of a one-to-many: the inline editor's when the collection is edited in its grid, else its line form's. A many-to-many holds references and has none.
      Returns:
      the line's spec, or null when the name is not a one-to-many of the model
    • at

      public FormSpec at(FormPath path)
      The spec of a node of the tree, following the path's collections.
      Throws:
      IllegalArgumentException - when a segment is not a one-to-many with lines
    • check

      public String check(FormStep step)
      Why a session would refuse the step, or null when it would run it: a path, field, button or chain the form does not have, an add on a collection without lines, a value a FormLimit.Kind.WIDGET field cannot hold. Positions and ids are not resolved: only a run knows the lines.
    • toString

      public String toString()
      Overrides:
      toString in class Object