Expand my Community achievements bar.

Server side validation - query


Level 1

I have a requirement to collect some info from casual visitor to the site (unauthenticated) using AEM Forms. On posting data to backend (custom rest endpoint), there may be some validation failures - in which case, the form should be rendered back to the user with the data filled in (whatever was just entered) along with an error message. The validation cannot be done from client side. I tried the 3 options below, none of them seem to work.

SlingHttpServletRequest wrappedErrorRequest = new CustomParameterRequest(slingRequest, "GET");

wrappedErrorRequest.setAttribute("error", "error details here");

wrappedErrorRequest.setAttribute("data", request.getParameter("jcr:data"));

//option 1

//slingRequest.getRequestDispatcher(slingRequest.getParameter(GuideConstants.SELF_URL) + ".html", options).forward(wrappedErrorRequest, response);

//option 2

GuideSubmitServlet.setForwardPath(slingRequest, slingRequest.getParameter(GuideConstants.SELF_URL)+ ".html", null,null );

//option 3

//GuideSubmitServlet.setRedirectUrl(slingRequest, slingRequest.getParameter(GuideConstants.SELF_URL + ".html");

In case of option 1 & 2, I get an error "resource cannot be modified". Turns out that I cannot forward to a page. With option 3, the request attributes are lost after the redirect. Any suggestions on how to resolve this?


2 Replies


Employee Advisor

Can you preserve the state of AF and try restoring it later. Check for getGuideState and restoreGuideState method in the GuideBridge API doc shared below :

Adaptive Forms Class: GuideBridge