IllegalArgumentException: null , java 播放框架
IllegalArgumentException: null , java play framework
我正在尝试从 html scala templete 表单中获取输入文本 jquery 该输入文本的值是日期,我将其传递给控制器以转换为日期格式然后在界面上重用但我得到空值,请帮助我。
Image error
scala 模板:
...........
<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));
}
......
问题出在我使用的 jquery 函数上,当您使用 $('#plot_marker').click(function(e){
e.preventDefault();
时它会阻止表单提交功能,并且播放框架将 post 方法视为 GET。
为了更正此错误,我使用了 Jquery 提交表单函数
$('plot_marker').click( function() {
$.post( '/searched/', $('form#mapform').serialize(), function(data) {
...
},
'json' // I expect a JSON response
);
});
Visit Whosebug answer
我正在尝试从 html scala templete 表单中获取输入文本 jquery 该输入文本的值是日期,我将其传递给控制器以转换为日期格式然后在界面上重用但我得到空值,请帮助我。
Image error
scala 模板:
...........
<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));
}
......
问题出在我使用的 jquery 函数上,当您使用 $('#plot_marker').click(function(e){
e.preventDefault();
时它会阻止表单提交功能,并且播放框架将 post 方法视为 GET。
为了更正此错误,我使用了 Jquery 提交表单函数
$('plot_marker').click( function() {
$.post( '/searched/', $('form#mapform').serialize(), function(data) {
...
},
'json' // I expect a JSON response
);
});
Visit Whosebug answer