use of com.day.cq.wcm.foundation.forms.FormsHandlingRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormActionRpcServlet method sendRedirect.
private void sendRedirect(ValueMap valueMap, SlingHttpServletRequest request, SlingHttpServletResponse response, boolean processFormApiSuccess) throws ServletException {
String redirect = getMappedRedirect(valueMap.get("redirect", String.class), request.getResourceResolver());
String errorMessage = valueMap.get("errorMessage", String.class);
FormsHandlingRequest formRequest = new FormsHandlingRequest(request);
try {
if (StringUtils.isNotEmpty(redirect) && processFormApiSuccess) {
response.sendRedirect(redirect);
} else {
if (!processFormApiSuccess && StringUtils.isNotEmpty(errorMessage)) {
ValidationInfo validationInfo = ValidationInfo.createValidationInfo(request);
validationInfo.addErrorMessage(null, errorMessage);
}
final Resource formResource = (Resource) request.getAttribute(ATTR_RESOURCE);
request.removeAttribute(ATTR_RESOURCE);
request.removeAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE);
RequestDispatcher requestDispatcher = request.getRequestDispatcher(formResource);
if (requestDispatcher != null) {
requestDispatcher.forward(formRequest, response);
} else {
throw new IOException("can't get request dispatcher to forward the response");
}
}
} catch (IOException var13) {
LOG.error("Error redirecting to {}", redirect);
}
}
Aggregations