1

I am using jQuery to show calendar, it perfectly work but when I submit the form backend does not receive the result >> result is null.

    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script>
        $(function() {
            $("#datepicker").datepicker();
        });

JSP:

   ...
   <s:textfield id="datepicker" name="datepicker"/>
   ...

Java:

  private String datepicker; 

  public String getDatepicker() {
      return datepicker;
  } 

  public void setDatepicker(String datepicker) {
     this.datepicker = datepicker;
  }

Generated HTML:

<input type="text" id="datepicker" value="" name="datepicker" class="hasDatepicker">
Roman C
  • 49,761
  • 33
  • 66
  • 176
J888
  • 1,944
  • 8
  • 42
  • 76

1 Answers1

1

The value is empty for your textfield, so you might try to set the value

<s:textfield id="datepicker" name="datepicker" value="%{datepicker}"/>

and make sure the params interceptor is configured to the action that submits the form enclosed the textfield above.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • I added the %{datepicker} and am using ModelDriven to catch the values of my form. Although, I am able to retrieve the value of all the values, I can not retrieve values of datepicker. – J888 Apr 14 '14 at 12:08
  • Is `setDatepicker` being invoked? – Roman C Apr 14 '14 at 12:12
  • it seems not, although all other fields of the ModelDriven object get populated. – J888 Apr 14 '14 at 12:19
  • Try to set it without `ModelDriven`, it adds unnecessary complexity to the code. – Roman C Apr 14 '14 at 12:33
  • the problem was with the modeldriven but I am not sure why! – J888 Apr 14 '14 at 12:52
  • Probably your interceptor stack needs modification. But it all looks useless without actual code. See also [this](http://stackoverflow.com/a/21282401/573032) answer if your names clashes with value stack. I don't know what them has downvoted it's proven and tested solution. – Roman C Apr 14 '14 at 13:01
  • If I didn't miss anything from you conversation, the problem wasn't related to the jQuery plugin at all and it was just a problem with the test field ? If that is the case maybe you could rephrase the question to focus on a Struts 2 action ot being able to get the value from a text field... – Pierre Henry Apr 15 '14 at 13:48