Maybe try changing from: "double" to "Double" for this line:
private double amount;
문제
I am beginner and using Spring 3.
I have following beans
public class Record {
private String title;
private double amount;
//Getter and Setter
}
public class RecordBean {
private List<Record> records;
public RecordBean() {
this.records = LazyList.lazyList(new ArrayList<Record>(), new InstantiateFactory<Record>(Record.class));
}
//Getter and Setter
}
I have added RecordBean
to model
modelMap.add('recordBean',new RecordBean());
Following is Spring Form
<form:form action="/save" method="POST" commandName="recordBean">
<form:input path="records[0].title"/>
<form:input path="records[0].amount"/>
<form:input path="records[1].title"/>
<form:input path="records[1].amount"/>
<input type="submit" value="Save"/>
</form:form>
I've also added InitBinder
to Controller
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true));
}
Now, if i enter value for amount[0]
and leave blank for amount[1]
and submit the form, i am getting typeMismatch
error.
Field error in object 'recordBean' on field 'records[1].amount': rejected value []; codes [typeMismatch.recordBean.records[1].amount,typeMismatch.recordBean.records.amount,typeMismatch.records[1].amount,typeMismatch.records.amount,typeMismatch.amount,typeMismatch.double,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [recordBean.records[1].amount,records[1].amount]; arguments []; default message [records[1].amount]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'double' for property 'records[1].amount'; nested exception is java.lang.NumberFormatException: empty String]
Please advise.
Thanks
올바른 솔루션이 없습니다
다른 팁
Maybe try changing from: "double" to "Double" for this line:
private double amount;