Class FormConditionsHandler

java.lang.Object
sk.iway.iwcm.components.multistep_form.rest.FormConditionsHandler

public class FormConditionsHandler extends Object
Helper class to evaluate form item conditions (visibility and requirement) based on both session data (previous steps) and received JSON data (current step). Provides methods to check if a field should be hidden or required, and to build JSON maps of conditions for frontend use. Caches conditions for performance, with cache invalidation when conditions are updated.
  • Constructor Details

    • FormConditionsHandler

      public FormConditionsHandler(String formName, jakarta.servlet.http.HttpServletRequest request)
  • Method Details

    • clearConditionsCache

      public static void clearConditionsCache(Long formItemId, Integer domainId)
    • isFieldHiddenByCondition

      @Nullable protected Boolean isFieldHiddenByCondition(FormItemEntity stepItem, org.json.JSONObject received)
      Check if a field should be hidden based on its visibility conditions. Evaluates conditions against both session data (previous steps) and received data (current step). Field is hidden when conditions are NOT met (inverse logic).
      Parameters:
      stepItem - the form item with potential visibility conditions
      received - the current step's submitted JSON data
      Returns:
      true if the field should be hidden (conditions NOT met), false if visible
    • isFieldRequiredByCondition

      @Nullable protected Boolean isFieldRequiredByCondition(FormItemEntity stepItem, org.json.JSONObject received)
      Check if a field should be required based on its REQUIREMENT conditions. Evaluates conditions against both session data (previous steps) and received data (current step). Field is required when conditions are met (direct logic).
      Parameters:
      stepItem - the form item with potential requirement conditions
      received - the current step's submitted JSON data
      Returns:
      true if the field should be required (all conditions met), false otherwise
    • getVisibilityConditions

      public final org.json.JSONObject getVisibilityConditions(Long stepId)
      Builds a map of visibility conditions for all items in a step. Each entry maps the item's fieldFormId to its conditions array and server-side hide flag. This separates visibility metadata from HTML rendering.
      Parameters:
      stepId - ID of the step
      Returns:
      JSONObject where keys are itemFormId and values are objects with "conditions" array and "hidden" boolean
    • getRequirementConditions

      public final org.json.JSONObject getRequirementConditions(Long stepId)
      Build a JSON map of requirement conditions for the given step. Structure mirrors getVisibilityConditions: keys are itemFormId, values contain "conditions" array and "required" boolean (true when cross-step conditions are all met).
      Parameters:
      stepId - ID of the step
      Returns:
      JSONObject where keys are itemFormId and values are objects with "conditions" array and "required" boolean