AオブジェクトであるB、Cオブジェクトを含む一般的なリストをバインドしようとしています。
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class A<T> {
@Column(name = "type", nullable = false, updatable = false, insertable = false)
private String type;
@Column(name = "value")
private String value;
// used to populate the value in the inner class
public abstract void setCustomValue(T value);
}
@DiscriminatorValue("b")
public class B extends A<Integer>{
public void setCustomValue(Integer value);
}
@DiscriminatorValue("c")
public class C extends A<Boolean>{
public void setCustomValue(Boolean value);
}
これは速度テンプレートとバインディング フォームです。
パブリック クラス AForm {
private List<A<?>> a;
public AForm() {
a = new ArrayList<A<?>>();
}
public AForm(List<A<?>> a) {
super();
this.a = a;
}
}
<form action="#springUrl("....")" method="post">
...
#foreach($a in $aList.a)
#set( $index = $velocityCount - 1 )
<tr>
<td>
#springFormInput("aList.a[$index].type" "")
</td>
<td>
#springFormInput("aList.a[$index].customValue" "")
</td>
</tr>
#end
...
<input type="submit" value="Save"/>
</form>
しかし、フォームを保存すると、フォーム内の各オブジェクトに指定されたタイプに応じて、スプリングはオブジェクト (B または C) ではなくオブジェクト A をインスタンス化しようとします。カスタムバインディングを作成する必要があると思いますが、その方法がわかりません。
ありがとう。