Search in sources :

Example 1 with FormsHandlingRequest

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);
    }
}
Also used : ValidationInfo(com.day.cq.wcm.foundation.forms.ValidationInfo) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) IOException(java.io.IOException) FormsHandlingRequest(com.day.cq.wcm.foundation.forms.FormsHandlingRequest) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

FormsHandlingRequest (com.day.cq.wcm.foundation.forms.FormsHandlingRequest)1 ValidationInfo (com.day.cq.wcm.foundation.forms.ValidationInfo)1 IOException (java.io.IOException)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)1 Resource (org.apache.sling.api.resource.Resource)1