Class FormModel

All Implemented Interfaces:
Element.DualDomNode, Peer

public class FormModel extends Model
A class to represent the result of joining a template and data.
  • Constructor Details

    • FormModel

      public FormModel(Element parent, Node prevSibling)
  • Method Details

    • getFormModel

      public static FormModel getFormModel(AppModel appModel, boolean bCreateIfNotFound)
      Returns the FormModel held within the AppModel.
      Parameters:
      appModel - the AppModel to search
      bCreateIfNotFound - if true, and the FormModel does not exist, then one will be created and returned; if false and the FormModel does not exist, null is returned
      Returns:
      the FormModel contained within appModel; null if not found and bCreateIfNotFound is false.
    • recurseConnectOnNode

      public static void recurseConnectOnNode(Node node, String strConnectionName, int eUsage, FormModel.ConnectHandler handler, Object handlerData)
    • addUseNode

      public void addUseNode(Element useNode)
      Description copied from class: Model
      add a new new node to the useNodeList
      Overrides:
      addUseNode in class Model
    • addUseHRefNode

      public void addUseHRefNode(Element useHRefNode)
      Not supported on FormModel
      Overrides:
      addUseHRefNode in class Model
    • clearFocus

      public void clearFocus()
      Resets the focus. No field will have focus after but the form model will remember which field had the focus last.
    • mergeMode

      public int mergeMode()
      Indicates whether the current merge mode is globally consumptive (XFAEnum::CONSUME_DATA) or not (XFAEnum::MATCH_TEMPLATE).
    • createNode

      public Node createNode(int eClassTag, Element parent, String aNodeName, String aNS, boolean bDoVersionCheck)
      Description copied from class: Model
      Create an element with the given tag, parent, name and uri.
      Specified by:
      createNode in class Model
      Parameters:
      eClassTag - the element's tag.
      parent - the element's parent.
      aNodeName - the element's name.
      aNS - the element's namespace.
      bDoVersionCheck - check the element's version.
      Returns:
      a new element.
      See Also:
    • createPanelOverlayData

      public void createPanelOverlayData(int nPanel)
      Creates an overlayData section under dataSets. This method is for Form Server support.
      Parameters:
      nPanel - the panel to create the overlayData section for
    • eventOccurred

      public boolean eventOccurred(String sActivity, Obj container)
      Notifies event listeners that an event has occurred on a container. This method may fire additional events before and/or after firing the event.
      Parameters:
      sActivity - the name of the event
      container - the container on which the event occurs
      Returns:
      true if one or more events were dispatched.
    • exportConnectionData

      public void exportConnectionData(String strConnectionName, String sDataDescriptionName)
    • getAdjustData

      public boolean getAdjustData()
      Determines whether the next remerge() operation will adjust the structure of the DataModel to match the TemplateModel. The default value is false.
      Returns:
      true if the next remerge() operation will adjust the structure of the DataModel to match the TemplateModel.
      See Also:
    • getAmbientLocale

      public String getAmbientLocale()
      Gets the ambient locale override for the top level subform. This will be used when resolving locales for fields and subforms. If a field/subform does not have a locale specified, then they will inherit it from their ancestory hierarchy.
      Returns:
      the ambient locale (e.g. "en_US").
    • getBaseNS

      public String getBaseNS()
      Specified by:
      getBaseNS in class Model
      See Also:
    • getCalculationsEnabled

      public boolean getCalculationsEnabled()
      Determines if calculations are enabled.
      Returns:
      true if calculations are enabled.
    • getDefaultValidate

      public FormModel.Validate getDefaultValidate()
      Gets the default Validate object. The default Validate object is used whenever validation is initiated by some method that does not use a Validate parameter, or when validation is initiated by validate(Validate, Element, boolean, boolean) or recalculate(boolean, Validate, boolean) and null is passed to the validate parameter. For example, the default Validate object is used when validation is initiated by the execValidate scripting method of the FormModel.
      Returns:
      a reference to an object derived from Validate, or null if no default Validate object has been set.
      See Also:
    • getDelta

      public Obj getDelta(Element node, String sSOM)
      Overrides:
      getDelta in class Model
    • getDeltas

      public Obj getDeltas(Element node)
    • getExecute

      public FormModel.Execute getExecute()
      Gets the Execute associated with this FormModel. May be null.
      Returns:
      the Execute.
    • getFocus

      public FormField getFocus()
      Gets the field that has focus for the FormModel.
      Returns:
      the field that has focus.
    • getFormStateRemoved

      public boolean getFormStateRemoved()
      Determines if the formState packet has been removed.
      Returns:
      true if the formState packet has been removed
    • getFriendlyName

      public String getFriendlyName(Element formNode)
      Gets the friendly name (to use in user-facing communication) for a form node
      Parameters:
      formNode - a FormSubform, FormField or FormExclGroup to get a user-friendly name for.
      Returns:
      a string containing a user-friendly name for the form node.
    • getHeadNS

      public String getHeadNS()
      Specified by:
      getHeadNS in class Model
      See Also:
    • getHost

      public HostPseudoModel getHost()
    • getOverlayDataMergeUsage

      public boolean getOverlayDataMergeUsage()
      Gets the OverlayDataMerge setting.
      Returns:
      true if OverlayDataMergeUsage must occur
    • getPanelToMergeAgainst

      public int getPanelToMergeAgainst()
      Gets the panel to merge against.
      Returns:
      the panel (second-level subform) to merge against
    • getPostMergeHandler

      public FormModel.PostMergeHandler getPostMergeHandler()
      Gets the callback method that is to be invoked after merge but before any initialization scripts are run.
      See Also:
    • getProtoList

      public List<ProtoableNode> getProtoList()
      Description copied from class: Model
      Keep track of proto Nodes and 'use' tags for quick lookup later our
      Overrides:
      getProtoList in class Model
      Returns:
      our list of protos
      See Also:
    • getRunScripts

      public int getRunScripts()
      Gets the runAt property that specifies where scripts should be executed (client, server or both). The default is both.
      Returns:
      one of: EnumAttr.RUNSCRIPTS_CLIENT, EnumAttr.RUNSCRIPTS_SERVER, EnumAttr.RUNSCRIPTS_BOTH or EnumAttr.RUNSCRIPTS_NONE
      See Also:
    • getScriptTable

      public ScriptTable getScriptTable()
      Overrides:
      getScriptTable in class Model
      See Also:
    • getServerExchange

      public FormModel.ServerExchange getServerExchange()
      Gets the ServerExchange implementation associated with this FormModel.
      Returns:
      a ServerExchange implementation, or null if no ServerExchange has been set.
      See Also:
    • getSubmit

      public FormModel.Submit getSubmit()
      Gets the Submit implementation associated with this FormModel.
      Returns:
      a pointer to a class derived from Submit.
    • getSubmitURL

      public String getSubmitURL()
      Gets the submit URL override for the top level subform. This will be used to determine if we are submitting to FormServer.
      Returns:
      String, the submit URL.
    • getValidationsEnabled

      public boolean getValidationsEnabled()
      Determines whether validations are enabled.
      Returns:
      true if validations are enabled.
    • importConnectionData

      public void importConnectionData(String strConnectionName)
    • importNode

      public Element importNode(ProtoableNode templateNode, Element formParent, boolean bFull)
      Imports a template node into this model, while resolving any global or dataRef fields. This will simply walk the template DOM and create a form node for each one it encounters. This will also set up the appropriate proto relationships
      Parameters:
      templateNode - the template node to import
      formParent - the parent we'll add the created form node too
      bFull - if true, do merge and process the children.
      Returns:
      the newly created Form node
    • initialize

      public boolean initialize()
      Fires the initialize event on all containers on the form, and fires the indexChange event on all subforms.
      Returns:
      true if one or more events were dispatched.
    • initializeNewContentNodes

      public boolean initializeNewContentNodes()
      Initializes the new content nodes
      Returns:
      true if one or more events were dispatched.
    • isCompatibleNS

      public boolean isCompatibleNS(String aNS)
      Description copied from class: Model
      Determine if a specified namespace string is compatible with the namespace of this model. Essentially this determines if the two namespaces are equivalent (though the strings that represent them may not be identical).
      Overrides:
      isCompatibleNS in class Model
      Parameters:
      aNS - The namespace to compare.
      See Also:
    • merge

      public void merge(boolean bEmptyMerge, boolean bAdjustData, boolean bInitialize, boolean bRestoreDeltas, boolean bForceRestore)
      Merges the TemplateModel and the DataModel to create the FormModel. The first two parameters are implicitly used to call setEmptyMerge(boolean) and setAdjustData(boolean) respectively.
      Parameters:
      bEmptyMerge - if true then merge against an empty DataModel, if false use the DataModel found in the AppModel
      bAdjustData - if true adjust the structure of the DataModel to match the structure of the TemplateModel; if false don't modify the DataModel.
      bInitialize - if true all the initialize events will be fired; if false no initialization is performed
      bRestoreDeltas - if true and if the restoreState property on the form's root subform is "auto" (the default is "manual"), all deltas are restored from the form packet. The locale attribute is always restored from the form packet, regardless of the value of this parameter.
      bForceRestore - if true, restore the state regardless of the the restoreState property on the form's root subform.
    • merge

      public void merge(boolean bEmptyMerge, boolean bAdjustData, String sConnectionName, boolean bInitialize, boolean bRestoreDeltas, boolean bForceRestore)
      Merges the TemplateModel and the DataModel to create the FormModel.
      Parameters:
      bEmptyMerge - if true then merge against an empty DataModel, if false use the DataModel found in the AppModel
      bAdjustData - if true, adjust the structure of the DataModel to match the structure of the TemplateModel; if false, don't modify the DataModel
      sConnectionName - if specified get all the data for the merge from the !connectionData.sConnectionName part of the DataModel. Also, use connect elements rather than bind elements of the TemplateModel
      bInitialize - if true, all the initialize events will be fired; if false, no initialization is performed
      bRestoreDeltas - if true and if the restoreState property on the form's root subform is "auto" (the default is "manual"), all deltas are restored from the form packet. The locale attribute is always restored from the form packet, regardless of the value of this parameter.
      bForceRestore - if true, restore the state regardless of the the restoreState property on the form's root subform.
    • mergeOverlayData

      public void mergeOverlayData(Node formNode, Node overlayData)
      Merges overlayData with a subform (FormServer requirement)
      Parameters:
      formNode - The subform to merge with
      overlayData - The data to merge with
    • normalizeNameSpaces

      public void normalizeNameSpaces()
      Overrides:
      normalizeNameSpaces in class Model
      See Also:
    • preSave

      public void preSave(boolean bSaveXMLScript)
      Description copied from class: Model
      Prepares this Model to be saved. Any model maintenance that may have been deferred is performed to ensure that the serialized form of the Model is correct. This method is called automatically before a Model is serialized to a stream, so it does not normally need to be called directly. The exception is when a Document is saved using Document.saveAs(java.io.OutputStream, Node, DOMSaveOptions) or Document.saveXML(java.io.OutputStream, DOMSaveOptions).
      Overrides:
      preSave in class Model
      See Also:
    • recalculate

      public boolean recalculate(boolean bFullRecalculate, FormModel.Validate validate, boolean bIgnoreCalcEnabledFlag)
      Executes calculation and validation scripts. After a merge operation, a full recalculate must be done to ensure that all calculations and validations are done using current data values. If data values are changed, this should be called to re-run the calculations.

      The FormModel tracks changes to data values, so recalculation efficiency can be improved by setting the bFullRecalculate parameter to false to perform only those calculations and validations that are dependent on the changed data values.

      Parameters:
      bFullRecalculate - if true all calculations and validations are run. If false calculations and validations are run as needed (i.e. if values that the validate or calculate script are dependent on have changed since the last recalculate).
      validate - an object derived from Validate. If null the default Validate is used, and if the default Validate is also null, no validations are performed.
      bIgnoreCalcEnabledFlag - if true the calculations will be performed even if they are disabled on the host.
      Returns:
      true if any calculations were performed
      See Also:
    • registerNewEvents

      public boolean registerNewEvents(boolean bAllow)
      Helper function to permit the temporary update the mbRegisterNewEvents setting This should call registerNewEvents(false) before cloning any form node to orphaned nodes being registered with the event model
      Parameters:
      bAllow - the new value of mbRegisterEvents
      Returns:
      the old value of mbRegisterEvents
    • remerge

      public void remerge()
      Forces the remerging of the DataModel and TemplateModel to recreate this FormModel. This is equivalent to calling merge(boolean, boolean, boolean, boolean, boolean), and specifying getEmptyMerge() and getAdjustData() for the bEmptyMerge and bAdjustData parameters, and specifying true, false, false for the bInitialize, bRestoreDeltas and bForceRestore parameters.
      See Also:
    • remove

      public void remove()
      Removes a FormModel from its parents child list. Since a FormModel can't really exist outside of the context of an AppModel (i.e., because of connections between the form and data models), the form gets reset before it is removed.
      Overrides:
      remove in class Model
      See Also:
    • removeReferences

      public void removeReferences(Node node)
      Recursively unmaps node from any DataNode it is mapped to.
      Overrides:
      removeReferences in class Model
      Parameters:
      node - the Node to be unmapped.
    • reset

      public void reset()
      Resets this FormModel to its initial state. All children are removed.
    • resetData

      public void resetData(Obj container)
      Resets a container to its template default value. If container is a field it will reset it. If container is a subform it will recursively reset all the containers it contains. If container is null then it will reset the root subform, and therefore all fields in the form.
      Parameters:
      container - the container to be reset
    • resolveProtos

      public void resolveProtos(boolean bForceExternalProtoResolve)
      Overrides:
      resolveProtos in class Model
    • restoreValidateDisableAll

      public void restoreValidateDisableAll(Element formNode, Node delta)
      restore the validate.disableAll property for a form node
    • setAdjustData

      public void setAdjustData(boolean bAdjustData)
      Sets whether the next remerge() operation will adjust the structure of the DataModel to match the structure of the TemplateModel.
      Parameters:
      bAdjustData - if true the next remerge() operation will adjust the structure of the DataModel to match the structure of the TemplateModel.
      See Also:
    • setAmbientLocale

      public void setAmbientLocale(String sLocale)
      Set the ambient locale override for the top level subform. This will be used when resolving locales for fields and subforms. If a field/subform does not have a locale specified, then they will inherit it from their ancestory hierarchy.
      Parameters:
      sLocale - the ambient locale (i.e. en_US).
    • setDefaultValidate

      public void setDefaultValidate(FormModel.Validate validate)
      Sets the default Validate. The default Validate is used during validation when validation is initiated by some method other than recalculate(boolean, Validate, boolean) or validate(Validate, Element, boolean, boolean), or when validate or recalculate are called and null is passed to the validate parameter. If no Validate instance is available, then no validations are performed.
      Parameters:
      validate - a reference to an object derived from Validate.
      See Also:
    • setEmptyMerge

      public void setEmptyMerge(boolean bEmptyMerge)
      Sets whether the next remerge() operation will do an empty merge. This property is also set implicity from the first parameter of any call to merge(boolean, boolean, boolean, boolean, boolean).
      See Also:
    • setExcludedActivities

      public void setExcludedActivities(String sExclude)
      Sets event activites that are to be excluded from execution.
      Parameters:
      sExclude - a space-delimited list of activities.
    • setExecute

      public void setExecute(FormModel.Execute execute)
      Associates an Execute object with this FormModel. This allows a client to execute a connection.
      Parameters:
      execute - an object derived from Execute. It will be cloned, so the original can be discarded. May be null.
    • setFocus

      public void setFocus(FormField field)
      Lets the form model know which field has focus.
      Parameters:
      field - the field that has focus.
    • setPostMergeHandler

      public void setPostMergeHandler(FormModel.PostMergeHandler handler, Object clientData)
      Sets the callback method that is to be invoked after merge but before any initialize scripts are run.
      Parameters:
      handler - the PostMergeHandler implementation to be invoked after merge but before any initialize scripts are run.
      clientData - this value will be passed as the parameter to FormModel.PostMergeHandler.handlePostMerge(Object) when the callback method is invoked.
      See Also:
    • setRunScripts

      public void setRunScripts(int eRunAtSetting)
      Sets the runAt property that specifies where scripts should be executed (client, server or both). The default is both.
      Parameters:
      eRunAtSetting - one of: EnumAttr.RUNSCRIPTS_CLIENT, EnumAttr.RUNSCRIPTS_SERVER, EnumAttr.RUNSCRIPTS_BOTH or EnumAttr.RUNSCRIPTS_NONE
      See Also:
    • setServerExchange

      public void setServerExchange(FormModel.ServerExchange serverExchange)
      Sets the ServerExchange implementation with this FormModel. This allows a form to invoke a web service.
      Parameters:
      serverExchange - an implementation ServerExchange. It will be cloned, so the original can be discarded. May be null.
      See Also:
    • setSubmit

      public void setSubmit(FormModel.Submit submit)
      Associates a Submit object with this FormModel. This allows a client to submit data to the server.
      Parameters:
      submit - an object derived from Submit. It will be cloned, so the original can be discarded. May be null.
    • setSubmitURL

      public void setSubmitURL(String sSubmitURL)
      Sets the submit URL from the config. This will be used to determine if we are submitting to FormServer.
      Parameters:
      sSubmitURL - the submit URL.
    • setValidateBeforeExecute

      public void setValidateBeforeExecute(boolean bValidate)
      Sets the flag for performing validations before executing.
      Parameters:
      bValidate - if true, validate before executing, don't validate otherwise.
    • setValidateBeforeSubmit

      public void setValidateBeforeSubmit(boolean bValidate)
      Sets the flag for performing validations before submitting.
      Parameters:
      bValidate - if true, validate before submitting, don't validate otherwise.
    • wasIncrementalMerge

      public boolean wasIncrementalMerge()
      Returns true if the last merge was an incremental merge.
    • setDisableFormRemerge

      public void setDisableFormRemerge(boolean bDisable)
      Disable/enable calls to remerge()
    • getDisableFormRemerge

      public boolean getDisableFormRemerge()
      Disable/enable calls to remerge()
    • setGlobalConsumption

      public void setGlobalConsumption(Boolean bVal)