Class ValidationService

java.lang.Object
fr.paris.lutece.portal.util.mvc.binding.validate.ValidationService

@ApplicationScoped public class ValidationService extends Object
Service responsible for validating method parameters and return values within the Lutece MVC framework using Jakarta Bean Validation (JSR-380).

This service integrates with the MVC binding mechanism to:

  • If they are also annotated with Valid, standard Jakarta validation constraints are applied.
  • If they are annotated with Validated, validation is performed using the specified validation groups (group-based validation).
In addition, method-level parameter validation is performed using an ExecutableValidator. The service also formats localized error messages for user-friendly feedback.

It uses Validator and ExecutableValidator for runtime validation of method arguments and return values.

  • Constructor Details

    • ValidationService

      public ValidationService()
      Default constructor.
  • Method Details

    • validateParameters

      public void validateParameters(Object resource, Method method, Object[] parameters)
      Validates the parameters of a controller method using Jakarta Bean Validation.

      This method performs validation on parameters annotated with ModelAttribute. For those parameters:

      • If they are also annotated with Valid, standard Jakarta validation constraints are applied.
      • If they are annotated with Validated, validation is performed using the specified validation groups (group-based validation).
      In addition, method-level parameter validation is performed using an ExecutableValidator.

      Parameters:
      resource - The controller/resource instance on which the method is invoked.
      method - The method whose parameters are being validated.
      parameters - The parameter values passed to the method.
    • validateReturnValue

      public void validateReturnValue(Object resource, Method method, Object returnValue)
      Validates the return value of a controller method using Jakarta Bean Validation.

      This method performs validation on the return value of a method annotated with Validated or Valid. It uses the ExecutableValidator to validate the return value against the method's constraints.

      Parameters:
      resource - The controller/resource instance on which the method is invoked.
      method - The method whose return value is being validated.
      returnValue - The return value of the method to validate.