Class ExtDirectResponseBuilder

java.lang.Object
ch.ralscha.extdirectspring.bean.ExtDirectResponseBuilder

public class ExtDirectResponseBuilder extends Object
An utility class that helps building the response for a FORM_POST method. The response is written directly into the ServletResponse.getOutputStream() with buildAndWrite().
  • Constructor Details

    • ExtDirectResponseBuilder

      public ExtDirectResponseBuilder(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Creates a builder that builds and writes the response of a FORM_POST method. Sets the successful flag to true, can be changed with the successful() and unsuccessful() methods.
      Parameters:
      request - the current http servlet request object
      response - the current http servlet response object
  • Method Details

    • create

      public static ExtDirectResponseBuilder create(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Creates a builder instance.
      Parameters:
      request - the current http servlet request object
      response - the current http servlet response object
      Returns:
      the created builder instance
      See Also:
    • setException

      public ExtDirectResponseBuilder setException(Exception exception)
      Creates an "exception" response. Calls BaseResponse.setType(String) with a value of "exception". Calls BaseResponse.setMessage(String) and BaseResponse.setWhere(String) according to the Configuration. This is a method primarily used for implementations of HandlerExceptionResolver.
      Parameters:
      exception - the exception that was thrown.
      Returns:
      this instance
    • addErrors

      public ExtDirectResponseBuilder addErrors(org.springframework.validation.BindingResult bindingResult)
      Adds an "errors" property in the response if there are any errors in the bindingResult. Sets the success flag to false if there are errors.
      Parameters:
      bindingResult -
      Returns:
      this instance
    • addErrors

      public ExtDirectResponseBuilder addErrors(Locale locale, org.springframework.context.MessageSource messageSource, org.springframework.validation.BindingResult bindingResult)
      Adds an "errors" property in the response if there are any errors in the bindingResult. Sets the success flag to false if there are errors.
      Parameters:
      locale -
      messageSource -
      bindingResult -
      Returns:
      this instance
    • addResultProperty

      public ExtDirectResponseBuilder addResultProperty(String key, Object value)
      Add additional property to the response.
      Parameters:
      key - the key of the property
      value - the value of this property
      Returns:
      this instance
    • successful

      public ExtDirectResponseBuilder successful()
      Sets success flag to true.
      Returns:
      this instance
    • unsuccessful

      public ExtDirectResponseBuilder unsuccessful()
      Sets success flag to false.
      Returns:
      this instance
    • setSuccess

      public ExtDirectResponseBuilder setSuccess(boolean flag)
      Sets success flag to the provided parameter.
      Parameters:
      flag - the new success value
      Returns:
      this instance
    • setJsonView

      public void setJsonView(Class<?> jsonView)
      Sets a specific JSON View (filter) that Jackson uses to serialize the response.
      Parameters:
      jsonView -
    • buildAndWrite

      public void buildAndWrite()
      Builds and writes the response into the OutputStream of HttpServletResponse . This methods has to be called at the end of a FORM_POST method.