I have a form being POST-ed to a custom end point which is implemented using a sling servlet. In this servlet, there is some backend validation done, based on which is we need to ask users to fill some data / fields again, if it does not meet business requirement.
But when the user is shown the SAME form again, there is a custom message need to be displayed. e.g "Value XXXXX is not a valid for this user."
Question - How do I send that information from slingservlet as response so that it is available in form ? Which jsp/js files do I modify ?
/Kanwal
Solved! Go to Solution.
Views
Replies
Total Likes
Joel Lucuik wrote...
Just decompiled the Java from the bundle. But formal docs would still be nice.
Joel
Thanks for your valuable feedback. The class got missed in the java documentation [1] We would update the same in the next release.
Views
Replies
Total Likes
Any thought on this one pls....
Alternatively, I can use ajax to submit the form to my servlet. But when I use this process, I loose the front end validations that are evaluated on window.guidebridge.submit(). So, I would have to do them in custom code. Is there a way to de-couple the validations and submit here so that my front end validations still apply but form is submitted using ajax
/Regards
Kanwal
Views
Replies
Total Likes
Hi Kanwaljit,
These are the answers to the three questions which you have asked,
a) Ajax Submit of adaptive form can be achieved using guideBridge#submit API. This API take an options object which consists of four members, (success, error, validate and context) as seen below.
/** * <p>Submits the adaptive form to the pre-configured submit action. It can also validate the adaptive form * before submission.</p> * * @param options {object} The signature of the object is * <pre><code> * { * validate: true, * success: function(guideResultObject) {}, * error: function(guideResultObject) {}, * context: obj * } * <table> * <tbody> * <tr> * <td>validate (optional)</td> * <td>object</td> * <td>If true validations are run, otherwise not</td> * </tr> * <tr> * <td>success (optional)</td> * <td>function</td> * <td>function called in case of success. An object of type {@link GuideResultObject} will be passed * as argument.<p><i><b>Note</b>: If provided, submit would be ajax submit.</i></p></td> * </tr> * <tr> * <td>error (optional)</td> * <td>function</td> * <td>function called in case of error. An object of type {@link GuideResultObject} will be passed * as argument</td> * </tr> * <tr> * <td>context (optional)</td> * <td>object</td> * <td>context will be used as <i>this</i> in the success/error handlers</td> * </tr> * </tbody> * </table> * @method * @memberof GuideBridge * @instance */ guideBridge.submit = function (options) {};
If there a success option passed, then the submit is an ajax submit.
b) To validate an adaptive form, you can make use of the guideBridge#validate API [1]
c) For passing messages to the client based on custom validations done on the server, you need to forward the request back with the required data. If you need to leverage the client side validation on the server, you can enable the server side validation option from Adaptive Form Container Dialog. If your validations are custom, then you can do something like this in your custom Submit action which you had created,
// Note: the CustomparameterRequest and GuideConstants are part of com.adobe.forms.common.submitutils // and com.adobe.aemds.guide.utils package // create a new sling http servlet request SlingHttpServletRequest wrappedErrorRequest = new CustomParameterRequest(request, wrappedParameterMap, "GET"); // set your custom error message as an attribute in request // so that you can use this in your page template to show it in client wrappedErrorRequest.setAttribute("error_list", <custom_error_list>); // Set the data attribute to restore the state of the adaptive form in this new request wrappedErrorRequest.setAttribute("data", request.getParameter("jcr:data")); // Create the dispatcher options with no suffix and selector RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSuffix(null); options.setReplaceSelectors(null); // Forward the request to the page request.getRequestDispatcher(request.getParameter(GuideConstants.SELF_URL) + ".html", options).forward(wrappedErrorRequest, response); // Now in your page template, check if error_list present and use it <c:if test="<%= request.getAttribute('error_list') != null%>"> // render the message in HTML </c:if>
[1] https://helpx.adobe.com/aem-forms/6/javascript-api/GuideBridge.html
Views
Replies
Total Likes
Are there docs for CustomParameterRequest?
I put null for wrappedParameterMap, and I got:
The constructor CustomParameterRequest(HttpServletRequest, null, String) is undefined.
Also tried HashMap.
Thanks, Joel
Views
Replies
Total Likes
Just decompiled the Java from the bundle. But formal docs would still be nice.
Joel
Views
Replies
Total Likes
Hi, I tried this and keep getting already committed errors.
We are using Adaptive forms with a custom submit via post.POST.jsp.
Suggestions?
"=============================================="
21.12.2016 15:45:28.885 *WARN* [0:0:0:0:0:0:0:1 [1482353128877] POST /content/forms/af/joel1/jcr:content/guideContainer.af.internalsubmit.jsp HTTP/1.1] com.adobe.aemds.guide.utils.SubmitDataCollector templateKey not found in merge json:autoSaveInfo
21.12.2016 15:45:28.962 *ERROR* [0:0:0:0:0:0:0:1 [1482353128904] POST /content/forms/af/joel1/jcr:content/guideContainer.af.submit.jsp HTTP/1.1] com.adobe.aemds.guide.servlet.GuideSubmitServlet Could not complete Submit Action due to Committed
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1243)
at org.eclipse.jetty.server.Response.sendRedirect(Response.java:705)
at org.eclipse.jetty.server.Response.sendRedirect(Response.java:714)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136)
...
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
21.12.2016 15:45:28.963 *ERROR* [0:0:0:0:0:0:0:1 [1482353128904] POST /content/forms/af/joel1/jcr:content/guideContainer.af.submit.jsp HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
com.adobe.aemds.guide.service.GuideException: Committed
at com.adobe.aemds.guide.servlet.GuideSubmitServlet.doPost(GuideSubmitServlet.java:287)
at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:149)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:345)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:376)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:546)
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44)
...
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1243)
at org.eclipse.jetty.server.Response.sendRedirect(Response.java:705)
at org.eclipse.jetty.server.Response.sendRedirect(Response.java:714)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136)
at org.apache.sling.engine.impl.log.RequestLoggerResponse.sendRedirect(RequestLoggerResponse.java:134)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136)
at com.adobe.aemds.guide.servlet.GuideSubmitServlet.doPost(GuideSubmitServlet.java:283)
... 114 common frames omitted
Views
Replies
Total Likes
Joel Lucuik wrote...
Just decompiled the Java from the bundle. But formal docs would still be nice.
Joel
Thanks for your valuable feedback. The class got missed in the java documentation [1] We would update the same in the next release.
Views
Replies
Total Likes
Question on the 3rd option mentioned in the response above
>>>>For passing messages to the client based on custom validations done on the server, you need to forward the request back with the required data. If you need to leverage the client side validation on the server, you can enable the server side validation option from Adaptive Form Container Dialog. If your validations are custom, then you can do something like this in your custom Submit action which you had created,
...
// Forward the request to the page
request.getRequestDispatcher(request.getParameter(GuideConstants.SELF_URL) + ".html", options).forward(wrappedErrorRequest, response);
..
the above is not working. I get an error "resource cannot be modified". Can we forward to a resource?
Views
Replies
Total Likes