java spring and ftl

Posted by bobby on Stack Overflow See other posts from Stack Overflow or by bobby
Published on 2009-08-26T11:57:51Z Indexed on 2010/05/25 23:01 UTC
Read the original article Hit count: 309

Filed under:
|

I defined a modelview object named "buttonpressed" in spring controller file and I need to access that modelview object in ftl(freemarker) file which is being returned as a view from a controller like abcd.java

The abcd.java controller code is as below

if (questionAnswer.getAnswerId() == 1045) 
  {
    modelAndView.addObject("buttonPressed","You have been added in mailing list");
    modelAndView.setViewName("enterCode_nextSteps");
  } 
else 
  {
    modelAndView.addObject("buttonPressed","Not added in the mailing list");
    modelAndView.setViewName("enterCode_nextSteps");
  }

the below ajax function is working fine currently but I am not sure how to access this object called "buttonpressed" in this ajax function. I have written like the way mentioned below but when i am clicking the submit link its not calling "partner.do" and also throwing error saying #buttonPressed is undefind (but in the script below its working fine and calling "partner.do" and even posting data)

So is that problem coming from javsscript code i mean due to incorrect use of "buttonPressed" or might be problem from spring controller abcd.java file.

<div class="partnerOptInBox">
  <div id="optInContent">
    <form name="partnerOptIn">
      <h4>Want the Latest</h4>
      <p class="pad10Top">${partnerOpt.translation}</p>
      <div class="pad10Top">
        <input type="radio" name="questionAnswer['${partnerOpt.questionId}']" value="${partnerOpt.getAnswers()[0].answerId}" class="radioButton" /> <label for="questionAnswer['${partnerOpt.questionId}']" class="formLabel pad20Right">Yes</label> <input type="radio" name="questionAnswer['${partnerOpt.questionId}']" class="radioButton" value="${partnerOpt.getAnswers()[1].answerId}" /> <label for="questionAnswer['${partnerOpt.questionId}']" class="formLabel">No</label>
      </div>
      <div id="optInError" class="formError" style="display:none;">Oops... your request did not go through, please try again.</div>
      <div class="pad15Top">
        <a href="javascript:submitOptIn();"><img src="images/theme/btn_opt_in_submit.gif"/></a>
      </div>	                       
    </form>
    <script type="text/javascript">
  function submitOptIn() {
    $('optInError').hide();
    dataString = $('#partnerOptIn').serialize();
    $.ajax({
    	data: dataString,
    	url: "partnerOpt.do",
    	timeout: 30000,
    	type: "POST",
       success: function(html){
        var newHtml = "<h4>Thank you</h4><p>We appreciate your time to respond to our request.</p>";
        $('#optInContent').html(newHtml);
},

*/trying this code for sucess is throwing me an error /*
<!-- buttonpressed function-->
    success: function(html){
      $('#optInContent').html(${buttonPressed});
    },

<!-- buttonpressed function-->

error: function(){
      $('#optInError').show();
      }
  });
}
</script>

© Stack Overflow or respective owner

Related posts about java

Related posts about spring