我刚接触百里香和春天。 我有一个对象SolicitudeCreateForm和一个InputValueCommandmentFormImpl列表,该列表还包含一个CommandmentOutputValue列表。
@InputValue(
tipo="type",
listaCommandments="valoresEntradaCom",
listaOffices="valoresEntradaOf"
)
public class SolicitudeCreateForm extends BaseEntityForm<Solicitude> {
@NotNull
private SolicitudeType type;
.....
@Valid
private List<InputValueCommandmentFormImpl> valoresEntradaCom;
.....
@PeriodDate(
startDate="startDate",
endDate="endDate",
canBeEquals=true
)
public class InputValueCommandmentFormImpl extends
BaseEntityForm<InputValueCommandment> implements IInputValueCommandmentForm {
/**
* the InputValueCommandmentCreateForm commandment sub type
*/
@NotNull
private CommandmentSubtype commandSubType;
/**
* the InputValueCommandmentCreateForm commandment sub type value
*/
@NotNull
private CommandmentSubtypeValue commandSubTypeValue;
/**
* the OutputValueCommandmentCreateForm commandment sub type value
*/
@NotNull
private List<CommandmentOutputValue> commandOutputTypeValue;
......
@Entity
@Table(name="commandments_sub_type_output_values")
public class CommandmentOutputValue extends ComboSolicitude {
/**
* CommandmentOutputValue extends ComboSolicitude class.
*
*/
/**
* the serialVersionUID constant.
*/
private static final long serialVersionUID = 1L;
@Column(name="defecto")
private Long defecto;
/**
* the Commandment sub type value commandment sub type
*/
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="sub_commandment_id", nullable=false, referencedColumnName="id")
private CommandmentSubtype commandmentSubtype;
public Long getDefecto() {
return defecto;
}
public void setDefecto(Long defecto) {
this.defecto = defecto;
}
/**
* @return the commandmentSubtype
*/
public CommandmentSubtype getCommandmentSubtype() {
return commandmentSubtype;
}
/**
* @param commandmentSubtype to set
*/
public void setCommandmentSubtype(CommandmentSubtype commandmentSubtype) {
this.commandmentSubtype = commandmentSubtype;
}
}
在我的模板中,我有一个用ajax填充的选择倍数
<div th:id="'valoresSalidaSelector' + ${iterStatus.index+1}" class="col-lg-12"
th:classappend="${!#lists.isEmpty(#fields.errors('valoresEntradaCom[__${iterStatus.index}__].commandOutputTypeValue')) ? 'has-error' : ''}">
<label class="control-label">[[#{solicitude.new.input.valores_salida}]]:</label>
<select th:id="'valoresSalida'+${iterStatus.index+1}" multiple="multiple" size="20" class="form-control dualListValoresSalida required"
th:name="${solicitude.valoresEntradaCom[__${iterStatus.index}__].commandOutputTypeValue}"
th:field="${solicitude.valoresEntradaCom[__${iterStatus.index}__].commandOutputTypeValue}"
th:with="subTypesValues=${enums.commandSubtypeOutputValRepo.findValueByCommandmentSubtype(solicitude.valoresEntradaCom[__${iterStatus.index}__].commandSubType)}"
>
<option th:each="commandOutputTypeValue : ${subTypesValues}" th:value="${commandOutputTypeValue.id}" th:title="${commandOutputTypeValue.name}">
[[${commandOutputTypeValue.name}]]
</option>
</select>
<th:block th:replace="fragments/field_errors :: errors ('valoresEntradaCom[__${iterStatus.index}__].commandOutputTypeValue')">
</div>
$.ajax({
method: "POST",
url: baseUrl()+"api/solicitudes/getSubCommandmentTypeOutputValues",
data: {data:valor},
dataType: "json",
success: function(json){
var $el = $("#valoresSalidaSelector"+id+ " select");
$el.empty();
for(var i=0; i < json.commandmentSubTypeOutputValues.length; i++){
if (json.commandmentSubTypeOutputValues[i].defecto == 1){
$el.append($("<option></option>")
.attr("value",json.commandmentSubTypeOutputValues[i]).attr("selected", "selected").text(json.commandmentSubTypeOutputValues[i].name));
}
else{
$el.append($("<option></option>")
.attr("value",json.commandmentSubTypeOutputValues[i]).text(json.commandmentSubTypeOutputValues[i].name));
}
}
$el.bootstrapDualListbox('refresh');
}
});
在浏览器中正确显示,但是当o尝试获取select的选定值时,i出现此错误
错误堆栈跟踪:
org.springframework.validation.BeanPropertyBindingResult:1个错误 字段上的对象“请求”中的字段错误 'valoresEntradaCom [0] .commandOutputTypeValue':拒绝的值[[object 宾语]];码 [typeMismatch.solicitude.valoresEntradaCom [0] .commandOutputTypeValue,typeMismatch.solicitude.valoresEntradaCom.commandOutputTypeValue,typeMismatch.valoresEntradaCom [0] .commandOutputTypeValue,typeMismatch.valoresEntradaCom.commandOutputTypeValue,typeMismatch.vallesEntradaCom; 论点 [org.springframework.context.support.DefaultMessageSourceResolvable: 码 [solicitude.valoresEntradaCom [0] .commandOutputTypeValue,valoresEntradaCom [0] .commandOutputTypeValue]; 参数[];预设讯息 [valoresEntradaCom [0] .commandOutputTypeValue]];预设讯息 [无法将类型'java.lang.String'的属性值转换为 属性所需的类型'java.util.List' 'valoresEntradaCom [0] .commandOutputTypeValue';嵌套异常为 java.lang.IllegalStateException:无法转换类型的值 'java.lang.String'为必需的类型 属性的'com.sopra.sgmj.entities.enums.CommandmentOutputValue' 'commandOutputTypeValue [0]':没有匹配的编辑器或转换 找到策略]
我完全迷路了,我不知道该怎么办。任何人都可以帮助我或给我小费吗?