Class FormConditionsHandler
java.lang.Object
sk.iway.iwcm.components.multistep_form.rest.FormConditionsHandler
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 Summary
ConstructorsConstructorDescriptionFormConditionsHandler(String formName, jakarta.servlet.http.HttpServletRequest request) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearConditionsCache(Long formItemId, Integer domainId) final org.json.JSONObjectgetRequirementConditions(Long stepId) Build a JSON map of requirement conditions for the given step.final org.json.JSONObjectgetVisibilityConditions(Long stepId) Builds a map of visibility conditions for all items in a step.protected BooleanisFieldHiddenByCondition(FormItemEntity stepItem, org.json.JSONObject received) Check if a field should be hidden based on its visibility conditions.protected BooleanisFieldRequiredByCondition(FormItemEntity stepItem, org.json.JSONObject received) Check if a field should be required based on its REQUIREMENT conditions.
-
Constructor Details
-
FormConditionsHandler
-
-
Method Details
-
clearConditionsCache
-
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 conditionsreceived- 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 conditionsreceived- the current step's submitted JSON data- Returns:
- true if the field should be required (all conditions met), false otherwise
-
getVisibilityConditions
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
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
-