IllegalArgumentException:null,java play framework

时间:2017-07-08 17:02:09

标签: jquery playframework playframework-2.0

我试图从html scala templete表单获取输入文本,jquery表示该输入文本的值是日期,我将它传递给控制器​​以转换为日期格式然后在接口上重用但我得到null价值,请帮助我。

Image error

scala tamplete:

 ...........

  <form  class="" role="form"   id="mapform">
                   <table width="1000" >
                    <tr>
                      <td width="500">
                          <div class="form-group col-sm-6">
                          <select name="names" class="form-control" 
id="dropdown" required="true">
                              <option value="">   </option>
                              @for(d <- Driver_registrationInfo.findAll()){
                                  <option id="namesId" name="names" value="@d.names"> @d.names </option>
                              }
                          </select>
                          </div>

                      </td>

                      <td width="500" >
                          <div class="form-group  col-sm-8">

                             <div class="col-lg-10">
                                  <div class='input-group date' id="datetimepicker8">
                                      <input type='text' class="form-control message"  id="datesfield"  name="dateSelect" required="true"/>
                                      <span class="input-group-addon">
                                          <i class="fa fa-calendar" aria-hidden="true"></i>
                                      </span>
                                  </div>
                              </div>
                          </div>

                      </td>

                      <td>
                          <div class="form-group ">

                          <input type='submit' class="form-control btn btn-danger" id="plot_marker" value="Track" />
                              </div>

.................

Jquery函数:

.....

$('#plot_marker').click(function(e){
e.preventDefault();

   var ioId2 = document.getElementById('datesfield').value;
   if(ioId2 ) {
    var nextUrl = "/searched/";
    window.location = nextUrl;
     }

......

控制器:

......

    public static Result searched() {
    Form<Coordinates> coordinatesForm = 
   Form.form(Coordinates.class).bindFromRequest();

    String names = coordinatesForm.field("names").value();
//  selected date on form convert it to string
    Date dateSelect = new 
   Date(coordinatesForm.field("dateSelect").value());
    DateFormat df = new SimpleDateFormat("yyy-MM-dd");
    String DateString = df.format(dateSelect);
    return ok(admin.render(names, DateString));
   }
     ......

1 个答案:

答案 0 :(得分:0)

问题是我正在使用的jquery函数,当你使用$('#plot_marker').click(function(e){ e.preventDefault();它阻止形式的submition功能时,play框架将post方法视为GET。

纠正此错误我使用Jquery提交表单函数

$('plot_marker').click( function() {
  $.post( '/searched/', $('form#mapform').serialize(), function(data) {
  ...
       },
       'json' // I expect a JSON response
   );
 });

Visit stackoverflow answer