Expand my Community achievements bar.

SOLVED

Difficulty on using Creating custom CQ email services example

Avatar

Level 6

I get the following error when trying to submit the email form.

 

Error

"javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}name" 

while processing /content/.../email2.json.jsp

                             
Status
500
Message
javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}name
Locationinvalid link: /content/ShopriteAfrica/English/email2.json.jsp/content/.../English/email2.json.jsp
Parent Location/content/.../English
Path
/content/.../English/email2.json.jsp
Refererhttp://localhost:4502/content/.../English/ContactUs.html
ChangeLog
<pre></pre>

Go Back

invalid link: /content/ShopriteAfrica/English/email2.json.jspModified Resource

Parent of Modified Resource

 

I have set up the following Action for my e-mail page 

 

<form action="email2.json.jsp" method="post" class="ajax">

....

             <div class="form__entry">
                <input type="submit" value="submit"  name="submit" id="submit" value="Submit" class="form__input form__submit" tabindex="7" >  
              </div>

 

 

The Javascript is 

  $('#contactSubmit').click(function() {
      var failure = function(err) {
          $(".main").unmask();
          alert("Unable to retrive data "+err);
          // TODO - clear the form
      };
       
      //Get the values to pass to the Mail OSGi bundle
      var server = $('#????').val() ;  // how to link
      var name = $('#name').val() ;  // how to link
      var surname = $('#surname').val() ;
      var email = $('#email').val() ; 
      var phoneNumber = $('#phoneNumber').val() ; 
      var enquiry = $('#enquiry').val() ;
       
      var url = location.pathname.replace(".html", "/contactus/email2.json.jsp") + "?to="+ to +"&server="+server +"&subject="+subject +"&message="+message;
       
      $(".main").mask("Sending...");
   
      $.ajax(url, {
          dataType: "text",
          success: function(rawData, status, xhr) {
               
              try {               
                  $(".main").unmask();
                  $('input[name"name"]').val('');                  
                  $('input[name"surname"]').val(''); 
                  $('input[name"email"]').val('');
                  $('input[name"phoneNumber"]').val('');
                  $('input[name"enquiry"]').val('');
                  $('#popup').show();
                 $('#popup').fadeOut(5000);
                      
   
                   
              } catch(err) {
                  failure(err);
              }
          },
          error: function(xhr, status, err) {
              failure(err);
          } 
      });
      
      return false;
    });
   
  }); 

 

 

And I am using a modified version of the email2.jason.jasp

1 Accepted Solution

Avatar

Correct answer by
Level 4
6 Replies

Avatar

Correct answer by
Level 4

Avatar

Level 2

Hi i have doubt in you given link .

am following same thing just i change from valid my mail id and smtp user also same but it is not working .

can you help me what code change it is working.

Thanks.

Avatar

Level 6

That is not a helpful reply, as I am not disputing that the basic tutorial works. If you read the code above, I am trying to apply the tutorial in a different context. I am using a different javascript, among others. I am not correctly specifying the url for the email2.json.jsp and I think that is the cause of my failure. This being a help forum I am looking to see if anyone can see what I have done wrong in the code I posted.

Avatar

Level 4

"javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}name" while processing /content/.../email2.json.jsp"

I see you are making call to jsp. I don't think it is possible to make call to jsp directly in CQ5.

"var url = location.pathname.replace(".html", "/contactus/email2.json.jsp") + "?to="+ to +"&server="+server +"&subject="+subject +"&message="+message;"

Few Questions:

What is the current page path?

What is the selector name? ex: json or email2 or email2.json

if the current page is http://localhost:4502/content/ShopriteAfrica/English/ContactUs.html and your selector is json or email2 then
 ajax call should be ContactUs.json.html or ContactUs.email2.html or ContactUs.email2.json.html not /contactus/email2.json.jsp.

Can you post the Selector based servlet which you have for sending email.

Avatar

Level 6

<%@ page import="org.apache.sling.commons.json.io.*,Shoprite.Africa.Nigeria.CustomEmailService" %><%
String server = request.getParameter("server");
String name = request.getParameter("name");
String surname = request.getParameter("surname");
String email = request.getParameter("email");
String phoneNumber = request.getParameter("phoneNumber");
String enquiry = request.getParameter("enquiry");


//Send the email message
CustomEmailService mailService = new CustomEmailService();
mailService.send(server,name,surname,email,"Contactus Form Generated EMail",phoneNumber,enquiry);  
%>

Avatar

Level 6

I found that the url to my Selector based servlet is 

http://localhost:4502/content/ShopriteAfrica/English/ContactUs.emailus.html

 

my call in ajax is 

 

            jQuery.get("ContactUs.emailus.html", {
                to: jQuery('input[name=name]', form),
                surname: jQuery('input[name=surname]', form),
                message: jQuery('input[name=message]', form)

}

 

This does not execute the emailus.jsp, is ContactUs.emailus.html incorrect.