Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3180

Add the capabilities to activate validation only in some cases

    XMLWordPrintableJSON

Details

    • Important

    Description

      Problem

      In our application, we have one form for the entire page because the user must decide (after a javascript confirmation) to save the data modified in all the block of the page. But in some case and if the user decide not saving all the modified page fields, we must only validate fields, the user want to save.

      STRUTS ParameterInterceptor and ValidationInterceptor interceptors don't offer a good solution for this problem : the only solution is to migrate the validation annotations to declare validation rules in an XML file (but there will be a lot of code duplication in this case) or coding rules by hand in a validate method.

      In our application, we found this trick but this is not elegant : we added a new interceptor ValidationFilterInterceptor that calls a method dynamically actionMethodValidationFilter (if the action method id actionMethod, the validationFilterInterceptor will call actionMethodValidationFilter) where we remove the "bad" errors (something like this : setFieldErrors(filterFieldErrorsOn("data2", getFieldErrors())));

      Proposal

      1. to add a new Annotation @ValidationCase(name="case1") that applies on the action method
      2. to add a new parameter validationCase in all Validation annotation ex : @RequiredValidator(key = "validation.required", validationCase=

      {"case1"}

      )
      3. to take into account in ParameterInterceptor and ValidationInterceptor, this annotation and new parameter in existing annotations to add conversion/validation rules only for the annotation linked to the "current" validation case.

      Attachments

        Activity

          People

            Unassigned Unassigned
            laurent.mimoun Laurent Mimoun
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: