title: java spring and ftl
body: <p>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 </p>
  
  <p>The abcd.java controller code is as below </p>
  
  <pre><code>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");
    }
  </code></pre>
  
  <p>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)</p>
  
  <p>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.</p>
  
  <pre><code>&lt;div class="partnerOptInBox"&gt;
    &lt;div id="optInContent"&gt;
      &lt;form name="partnerOptIn"&gt;
        &lt;h4&gt;Want the Latest&lt;/h4&gt;
        &lt;p class="pad10Top"&gt;${partnerOpt.translation}&lt;/p&gt;
        &lt;div class="pad10Top"&gt;
          &lt;input type="radio" name="questionAnswer['${partnerOpt.questionId}']" value="${partnerOpt.getAnswers()[0].answerId}" class="radioButton" /&gt; &lt;label for="questionAnswer['${partnerOpt.questionId}']" class="formLabel pad20Right"&gt;Yes&lt;/label&gt; &lt;input type="radio" name="questionAnswer['${partnerOpt.questionId}']" class="radioButton" value="${partnerOpt.getAnswers()[1].answerId}" /&gt; &lt;label for="questionAnswer['${partnerOpt.questionId}']" class="formLabel"&gt;No&lt;/label&gt;
        &lt;/div&gt;
        &lt;div id="optInError" class="formError" style="display:none;"&gt;Oops... your request did not go through, please try again.&lt;/div&gt;
        &lt;div class="pad15Top"&gt;
          &lt;a href="javascript:submitOptIn();"&gt;&lt;img src="images/theme/btn_opt_in_submit.gif"/&gt;&lt;/a&gt;
        &lt;/div&gt;                           
      &lt;/form&gt;
      &lt;script type="text/javascript"&gt;
    function submitOptIn() {
      $('optInError').hide();
      dataString = $('#partnerOptIn').serialize();
      $.ajax({
          data: dataString,
          url: "partnerOpt.do",
          timeout: 30000,
          type: "POST",
         success: function(html){
          var newHtml = "&lt;h4&gt;Thank you&lt;/h4&gt;&lt;p&gt;We appreciate your time to respond to our request.&lt;/p&gt;";
          $('#optInContent').html(newHtml);
  },
  
  */trying this code for sucess is throwing me an error /*
  &lt;!-- buttonpressed function--&gt;
      success: function(html){
        $('#optInContent').html(${buttonPressed});
      },
  
  &lt;!-- buttonpressed function--&gt;
  
  error: function(){
        $('#optInError').show();
        }
    });
  }
  &lt;/script&gt;
  </code></pre>