Interface FormScope


  • public interface FormScope
    The form values and other state variables are stored server-side in what is called the form scope. The form scope is a hierachy of scopes; for each BasicFormFragmentContainer, a new nested and named scope exists. This class represents a single node in such a scope, and is the interface that is used by most FormLogicComponents for accessing the scope. Information not found in the current scope is automatically looked up in the parent scope.
    • Method Detail

      • setFragmentValue

        void setFragmentValue​(String fragment,
                              Object value)
        Updates a fragment value in the current local scope
        Parameters:
        fragment - the identifier of the fragment
        value - the new value of the fragment
      • setFragmentValues

        void setFragmentValues​(String fragment,
                               List<Object> values)
        Updates fragment values in the current local scope. This method is meant for fragments with multiple values.
        Parameters:
        fragment - the identifier of the fragment
        values - the new values of the fragment.
      • getFragmentValue

        Object getFragmentValue​(String fragment)
        Returns a single value of the fragment with the specified identifier. This method returns nothing when the fragment has or can have multiple values.
        Parameters:
        fragment - the identifier of the fragment for which to return the value
        Returns:
        the value of the fragment with the specified identifier
      • getFragmentValues

        List<Object> getFragmentValues​(String fragment)
        Returns all fragment values of the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment to return the values for
        Returns:
        the values of the fragment with the specified identifier
      • setUploadFragmentValue

        void setUploadFragmentValue​(String fragment,
                                    UploadedFile file)
        Sets a fragment value for a file upload fragment.
        Parameters:
        fragment - the identifier of the fragment
        file - the uploaded file
      • setUploadFragmentValues

        void setUploadFragmentValues​(String fragment,
                                     List<UploadedFile> files)
        Sets fragment values for a file upload fragment.
        Parameters:
        fragment - the identifier of the fragment
        files - the uploaded files
        Since:
        10.33.0
      • getFragmentScope

        FragmentScope getFragmentScope​(String fragment)
        Returns the underlying FragmentScope. This is either a FragmentScope or an UploadFragmentScope.
        Parameters:
        fragment - the identifier of the fragment to return the value for
        Returns:
        the fragment scope
      • setFragmentPrefilling

        void setFragmentPrefilling​(String fragment,
                                   String value)
        Updates a fragment prefilling value in the current local scope
        Parameters:
        fragment - the identifier of the fragment
        value - the new value of the prefilling
      • getFragmentPrefilling

        String getFragmentPrefilling​(String fragment)
        Returns the prefilling value of the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment for which to return the prefilling value
        Returns:
        the prefilling value of the fragment with the specified identifier
      • setFragmentCondition

        void setFragmentCondition​(String fragment,
                                  Boolean value)
        Updates the condition that indicates whether a fragment should be shown or not.
        Parameters:
        fragment - the fragment for which to update the condition
        value - the value of the condition
      • getFragmentCondition

        Boolean getFragmentCondition​(String fragment)
        Returns the condition that indicates whether a fragment should be shown or not.
        Parameters:
        fragment - the fragment for which to update the condition return the value of the condition
      • addFragmentError

        void addFragmentError​(String fragment,
                              String code,
                              String message)
        Adds an error message for the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment for which to add an error message
        code - the error code
        message - the error message
      • getFragmentErrors

        Map<String,​Object> getFragmentErrors​(String fragment)
        Returns a Map containing all error codes and message for the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment for which to return the errrors
        Returns:
        a Map containing all errors for this fragment
      • clearFragmentErrors

        void clearFragmentErrors​(String fragment)
        Clears all errors for the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment for which to clear the list or errors
      • addFragmentMessage

        void addFragmentMessage​(String fragment,
                                String code,
                                String message)
        Adds a message for the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment for which to add a mesage
        code - the code of the message
        message - the message itself
      • getFragmentMessages

        Map<String,​Object> getFragmentMessages​(String fragment)
        Returns all messages for the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment for which to return all messages
        Returns:
        all messages
      • clearFragmentMessages

        void clearFragmentMessages​(String fragment)
        Clears all messages for the fragment with the specified identifier.
        Parameters:
        fragment - the identifier of the fragment
      • addContainerError

        void addContainerError​(String code,
                               String message)
        Adds an error to the fragment container. This is meant for - e.g. - FormSteps of FormSections.
        Parameters:
        code - the code of the error
        message - the error message itself
      • getContainerErrors

        Map<String,​Object> getContainerErrors()
        Returns all errors for the container (e.g. the FormStep or a FormSection).
        Returns:
        a map of error codes and messages
      • clearContainerErrors

        void clearContainerErrors()
        Clears all container error messages.
      • addContainerMessage

        void addContainerMessage​(String code,
                                 String message)
        Adds a message for the container (e.g. the FormStep or a FormSection).
        Parameters:
        code - the code of the message
        message - the message itself.
      • getContainerMessages

        Map<String,​Object> getContainerMessages()
        Returns all container messages.
        Returns:
        a Map of message codes and messages for the container
      • clearContainerMessages

        void clearContainerMessages()
        Clears all container messages in the local scope.
      • setCondition

        void setCondition​(Boolean condition)
        Sets the value of the condition.
        Parameters:
        condition - true or false or null if no condition was specified
      • getCondition

        Boolean getCondition()
        The value of the condition.
        Returns:
        true or false or null if no condition was specified
      • getOrCreateNestedScope

        FormScope getOrCreateNestedScope​(String identifier)
        Creates a nested scope for a nested container.
        Parameters:
        identifier - the identifier of the nested scope
        Returns:
        the nested scope
      • evaluateCondition

        boolean evaluateCondition​(String condition,
                                  String name)
        Evaluates a condition within this scope
        Parameters:
        condition - the condition, a JavaScript expression
        name - name of the condition to evaluate
        Returns:
        the boolean result of the condition
      • evaluateExpression

        Object evaluateExpression​(String expression,
                                  String name)
        Evaluates an expression within this scope
        Parameters:
        expression - the JavaScript expression
        name - name of the expression to evaluate, mainly for debugging and logging purposes
        Returns:
        the result of the condition
      • interpolateString

        String interpolateString​(String string,
                                 String name)
        Interpolates a String with JavaScript expressions contained between dollar-signs.
        Parameters:
        string - the string that may or may not contain expressions contained between dollar-signs
        name - name of the string, mainly for debugging and logging purposes
        Returns:
        the string with each dollar-delimited javascript-expression replaced with its evaluated result
      • getNestedPath

        String getNestedPath()
        Returns the nested path of this "node" in the scope.
        Returns:
        the nested path of this "node" in the scope
      • setLocale

        void setLocale​(String locale)
        Sets the locale to use for language specific messages.
        Parameters:
        locale - the locale to use for language specific messages
      • getLocale

        String getLocale()
        Returns the locale to use for language specific messages.
        Returns:
        the locale to use for language specific messages
      • hasErrors

        boolean hasErrors()
        Returns whether errors are present in this scope.
        Returns:
        true if errors are present in this scope
      • clearErrors

        void clearErrors()
        Recursively removes all errors for this FormScope and underlying objects.
      • clearMessages

        void clearMessages()
        Recursively removes all messages for this FormScope and underlying objects.
      • getFormEngineSession

        FormEngineSession getFormEngineSession()
        Returns the form engine session in which this scope "lives".
        Returns:
        the form engine session in which this scope "lives"
      • setFormEngineSession

        void setFormEngineSession​(FormEngineSession session)
        Sets the form engine session in which this scope "lives".
        Parameters:
        session - the form engine session in which this scope "lives"
      • getRootScope

        FormScope getRootScope()
        Returns the root FormScope.
        Returns:
        the root FormScope
      • put

        Object put​(String key,
                   Object value)
        Stores a value in the scope.
        Parameters:
        key - the key to store the value under
        value - the value to be stored
        Returns:
        the previous value or null if there was none
      • get

        Object get​(Object key)
        Returns the value stored under the specified key.
        Parameters:
        key - the key to return the value for
        Returns:
        the value stored under the key or null if there was none
      • getOrCreateUploadFragmentScope

        UploadFragmentScope getOrCreateUploadFragmentScope​(String identifier)
        Creates a nested scope for an upload form fragment
        Parameters:
        identifier - the identifier of the upload form fragment
        Returns:
        the upload form fragment scope
      • isPrepared

        boolean isPrepared()
        Returns true if the FormScope, which contains the step values, is prepared. This means that the prefilling is done and the conditions are updated.
        Returns:
        true if the formscope is prepared
      • setPrepared

        void setPrepared​(boolean prepared)
        Sets the prepared state of the formscope.
        Parameters:
        prepared - indicating if the step is prepared