Module ch.ralscha.extdirectspring
Package ch.ralscha.extdirectspring.bean
Class ExtDirectResponseBuilder
java.lang.Object
ch.ralscha.extdirectspring.bean.ExtDirectResponseBuilder
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 Summary
ConstructorsConstructorDescriptionExtDirectResponseBuilder(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Creates a builder that builds and writes the response of a FORM_POST method. -
Method Summary
Modifier and TypeMethodDescriptionaddErrors(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.addErrors(org.springframework.validation.BindingResult bindingResult) Adds an "errors" property in the response if there are any errors in the bindingResult.addResultProperty(String key, Object value) Add additional property to the response.voidBuilds and writes the response into the OutputStream ofHttpServletResponse.static ExtDirectResponseBuildercreate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Creates a builder instance.setException(Exception exception) Creates an "exception" response.voidsetJsonView(Class<?> jsonView) Sets a specific JSON View (filter) that Jackson uses to serialize the response.setSuccess(boolean flag) Sets success flag to the provided parameter.Sets success flag to true.Sets success flag to false.
-
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 thesuccessful()andunsuccessful()methods.- Parameters:
request- the current http servlet request objectresponse- 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 objectresponse- the current http servlet response object- Returns:
- the created builder instance
- See Also:
-
setException
Creates an "exception" response. CallsBaseResponse.setType(String)with a value of "exception". CallsBaseResponse.setMessage(String)andBaseResponse.setWhere(String)according to theConfiguration. This is a method primarily used for implementations ofHandlerExceptionResolver.- 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
Add additional property to the response.- Parameters:
key- the key of the propertyvalue- the value of this property- Returns:
- this instance
-
successful
Sets success flag to true.- Returns:
- this instance
-
unsuccessful
Sets success flag to false.- Returns:
- this instance
-
setSuccess
Sets success flag to the provided parameter.- Parameters:
flag- the new success value- Returns:
- this instance
-
setJsonView
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 ofHttpServletResponse. This methods has to be called at the end of a FORM_POST method.
-