Expand my Community achievements bar.

SOLVED

Unable to submit AEM adaptive form to internal servlet from local author instance

Avatar

Level 1

Hi,

 

I am trying to submit an adaptive form with three fields to an internal servlet /bin/sling/adaptiveformssubmit

 

I followed the steps here and created the below configs

 

priyadarshi_cts_0-1589458877027.png    priyadarshi_cts_1-1589458984765.png  

I added the below configs in the submit section.

priyadarshi_cts_2-1589459083175.png

I always get the default message "Thank you for submitting the form." and the form data does not reach the back end servlet.

This is my post.POST.jsp

 

<%@include file="/libs/fd/af/components/guidesglobal.jsp" %>
<%@page import="org.apache.sling.api.resource.ResourceUtil,
com.adobe.cq.social.commons.CollabUtil,
org.apache.sling.jcr.api.SlingRepository,
org.apache.sling.api.resource.ValueMap,
java.util.concurrent.atomic.AtomicInteger,
org.slf4j.Logger,
org.slf4j.LoggerFactory,
org.apache.sling.jcr.base.util.AccessControlUtil,
org.apache.jackrabbit.api.security.user.UserManager,
com.adobe.aemds.guide.service.GuideStoreContentSubmission,
javax.jcr.security.Privilege,
java.util.HashMap,
javax.jcr.Session,
javax.jcr.Node,
javax.jcr.security.AccessControlList,
javax.jcr.security.AccessControlPolicyIterator,
javax.jcr.security.AccessControlManager,
javax.jcr.security.AccessControlPolicy,
com.day.cq.commons.jcr.JcrUtil,
com.adobe.aemds.guide.servlet.GuideSubmitServlet,
com.adobe.aemds.guide.utils.GuideConstants,
com.day.cq.wcm.foundation.forms.FormsHelper" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>

<% final AtomicInteger uniqueIdCounter = new AtomicInteger();

%>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>
<%
%>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %>
<cq:defineObjects/><sling:defineObjects/>
<%
log.info("Inside Contact Us!");
FormsHelper.runAction("/bin/sling/adaptiveformssubmit", "post", resource,
slingRequest, slingResponse);
//GuideSubmitServlet.setForwardPath(slingRequest, "/bin/sling/adaptiveformssubmit", null, null);

%>

I have also tried to directly link the servlet as a REST Endpoint like below 

priyadarshi_cts_3-1589459388439.png

This throws a 500 error on the page.

priyadarshi_cts_4-1589459478457.png

Please let me know if I am missing any configurations for the submit action to work on a servlet

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 9

you will have to parse the submitted data as xml in your servlet which handles the form submission and then fetch the appropriate elements value using xpath or org.w3c.dom.Document methods 

View solution in original post

7 Replies

Avatar

Level 1
Hi, I tried this above approach. However, I can't seem to get the values in the back end through request.getParameter(). I have named the textbox field "username". But when I try to get the value with request.getParameter("username"), I always get NULL as the param is not present.

Avatar

Level 9

Can you please enumerate through all the request parameters and write the parameter names to the log file

use request.getParameterNames and the. Loop through the enumeration 

I think you will find a request parameter called jcr:data which will have the data submitted 

Avatar

Level 1

I tried to get the names, it comes as empty. I enabled the logs on AEM, I see the following entry. Not sure if we need to specifically mention the encoding type anywhere in the forms.

 

com.adobe.aemds.guide.service.impl.RESTSubmitActionService RESTSubmitActionService: Content type is either is null or does not contain application/x-www-form-urlencoded

Avatar

Level 9

Can you please check if the servlet resolver is resolving correctly to your servlet path

also can you please paste your servlet code?

 

Avatar

Level 1

okay, the problem was my tomcat server was not configured to accept the multiform data. Now I am getting the values back into my servlet. However, it is coming as "jcr:data" and "dataXml" with identical content

 

"<afData><afUnboundData><data><username>testing user</username><password>testing password</password></data></afUnboundData><afBoundData><data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"/></afBoundData><afSubmissionInfo><computedMetaInfo/><signer...>"

 

Is there any OOTB configuration which can transform to a normal HTTP POST request that can be retrieved by request.getParameter("username") ? Or this has to be a custom submit action to send the values to be servlet in that format?

Avatar

Correct answer by
Level 9

you will have to parse the submitted data as xml in your servlet which handles the form submission and then fetch the appropriate elements value using xpath or org.w3c.dom.Document methods