Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

forward.jsp issue in custom form action with AEM 6.2

Avatar

Level 4

I am migrating from AEM 5.6.1 to AEM 6.2. I have a custom mail action with a forward.jsp which sets some attributes to the sling request. This component works fine in AEM 5.6.1.  However, after updating to AEM 6.2, the forward.jsp is not being invoked while clicking submit. Instead the POST servlet is invoked directly. Any idea what is going wrong?

Paul

1 Accepted Solution

Avatar

Correct answer by
Level 4

This has happened since one of the form field component within (dropdown component) has the target option clicked from edit bar. This was the reason for the forward.jsp not being invoked. After reverting to the original configuration it worked. Took a bit of time to investigate as there are around hundreds of form fields. Might help someone if come across something similar... 

View solution in original post

3 Replies

Avatar

Administrator

Hi

Can you please share with us if any error is coming up?

in meanwhile, please have a look at this Adobe Helpx article:

Link:- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Video :-https://www.youtube.com/watch?v=RbI38z5SAnM&feature=youtu.be

// Submitting Adobe Experience Manager form data to Java Sling Servlets

Here in this article, we are submitting a form data by Ajax call to Sling servlet.

Call:

$('#submit').click(function() {
    var failure = function(err) {
             alert("Unable to retrive data "+err);
   };  
    //Use JQuery AJAX request to post data to a Sling Servlet
    $.ajax({
         type: 'POST',   
         url:'/bin/mySearchServlet',
         data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
         success: function(msg){
 
           var json = jQuery.parseJSON(msg);
            var msgId=   json.id;
            var lastName = json.lastname;
            var firstName = json.firstname;
              
            $('#ClaimNum').val(msgId);
            $('#json').val("Filed by " + firstName + " " + lastName);  
         }
     });
  });

Handler

     protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {}
       

Packages :- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets/_jcr_content/main-pars/downlo...

I hope this should help you.

~kautuk

Avatar

Level 4

kautuksahni wrote...

Hi

Can you please share with us if any error is coming up?

in meanwhile, please have a look at this Adobe Helpx article:

Link:- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Video :-https://www.youtube.com/watch?v=RbI38z5SAnM&feature=youtu.be

// Submitting Adobe Experience Manager form data to Java Sling Servlets

Here in this article, we are submitting a form data by Ajax call to Sling servlet.

Call:

$('#submit').click(function() {
    var failure = function(err) {
             alert("Unable to retrive data "+err);
   };  
    //Use JQuery AJAX request to post data to a Sling Servlet
    $.ajax({
         type: 'POST',   
         url:'/bin/mySearchServlet',
         data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
         success: function(msg){
 
           var json = jQuery.parseJSON(msg);
            var msgId=   json.id;
            var lastName = json.lastname;
            var firstName = json.firstname;
              
            $('#ClaimNum').val(msgId);
            $('#json').val("Filed by " + firstName + " " + lastName);  
         }
     });
  });

Handler

     protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {}
       

Packages :- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets/_jcr_content/main-pars/downlo...

I hope this should help you.

~kautuk

 

Thanks for sharing this...

However, I have a slightly bit different use case as I am not using ajax.

Strangely there is no exception also on the log files. I get a null pointer from one of the Method within my Custom servlet. The value is expected to be set in forward.jsp (something like below) which is not being executed and hence not being set.

 

<%@include file="/libs/foundation/global.jsp"%>     
<%@page session="false" %><%
%><%@page import="com.day.cq.wcm.foundation.forms.FormsHelper"%><%
%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
%>
<%@page import="com.day.cq.wcm.foundation.forms.FormsConstants"%><sling:defineObjects/><%
    slingRequest.setAttribute("mailto", (String[]) properties.get("mailto", String[].class));
    slingRequest.setAttribute("redirect", properties.get("redirect", ""));
    slingRequest.setAttribute("htmlEmailTemplatePath", properties.get("htmlEmailTemplatePath", ""));
    slingRequest.setAttribute("errorRedirect", properties.get("errorRedirect", ""));
    FormsHelper.setForwardPath(slingRequest,  "/bin/customServlet.html" );
    FormsHelper.setRedirectToReferrer(request, true);
%>

Avatar

Correct answer by
Level 4

This has happened since one of the form field component within (dropdown component) has the target option clicked from edit bar. This was the reason for the forward.jsp not being invoked. After reverting to the original configuration it worked. Took a bit of time to investigate as there are around hundreds of form fields. Might help someone if come across something similar...