1 Reply Latest reply on May 15, 2009 2:52 AM by rschoeler

    Passing date types with jsFunction or commandLink

    gwzoller

      Hello,

      I'm trying (unsuccessfully) to pass a date object back to the server side via jsFunction. I'm using a jQuery UI datepicker, but that shouldn't be relevant. When a date is selected the onSelect function is called, which calls my jsFunction code with (in this example) a fixed date. Code below:

       <a4j:jsFunction name="sendDate1">
       <a4j:actionparam name="date1" assignTo="#{dateMgr.date1}" />
       </a4j:jsFunction>
       <script class="javascript">
       var foo = jQuery.datepicker.parseDate("mm/dd/yy", "05/20/2009"); // create js date obj
       jQuery(".inlineDatePicker").datepicker({
       inline: true,
       onSelect: function(dateText) { sendDate1(foo); }
       });
       </script>
      
       <!-- Doesn't work either -->
       <a4j:commandLink value="Click Me!" ajaxSingle="true" action="#{dateMgr.setDate1(foo)}"/>
      
      
      // Java Server-Side Code
       public void setDate1(Date date1) {
       this.date1 = date1;
       System.out.println("date1 set to "+date1);
       }
      
      


      What happens is that the ajax call does fire but passes null in the post, and thereby setting the server-side bean parameter to null.

      I've passed Strings like this before but I don't want to wimp out and convert all my server-side dates to strings if I can avoid it. I should be able to pass JS Dates, shouldn't I?

      Any ideas how to do this right?
      Thanks!
      Greg