私のシナリオでは、BeanにバインドされたJSPでネストされたselectを開発しています。
豆
public class WizardPanelp1Bean {
private Integer id;
private Stringofpanels stringofpanels;
private Paneltype paneltype;
private Integer number;
private String paneltypestring;
//and getters/setters... [Omitted]
これで、Paneltypeオブジェクト、別の単純なBeanができました。
パネルタイプ
private Integer id;
private double peakpower;
private double weight;
private String name;
private double dimension;
private double conversion;
private Set functions = new HashSet(0);
private Set sensors = new HashSet(0);
private Set panels = new HashSet(0);
//[Getters/setters omitted as usual]
そこで、wbという名前のBeanを使用して 、パネルの単純な配列リストを使用してビューを準備します。
public class PanelsBean {
private ArrayList<WizardPanelp1Bean> panels =new ArrayList<WizardPanelp1Bean>();
そして最後に私はjspに行きます(これはにあることに注意してください)
<tbody>
<c:forEach items="${wb.panels}" varStatus="loop" var="item">
<tr>
<td>${item.id}</td>
<td>
<form:select path="panels[${loop.index}].paneltype" >
<c:forEach var="type" items="${types}">
<c:choose>
<c:when test="${item.paneltype.id==type.id}">
<form:option selected="selected" value="${type.id}" label="${type.name}" />
</c:when>
<c:otherwise>
<form:option value="${type.id}" label="${type.name}" />
</c:otherwise>
</c:choose>
</c:forEach>
</form:select>
</td>
<td><form:input style="width:180px" path="panels[${loop.index}].number" /></td>
<td>
<div>
<form:input style="visibility: hidden ; width:0px" path="panels[${loop.index}].id" disabled="disabled" />
<a href="javascript:remove(${item.id},${stringofpanels.id})" class="wb.panels.remove" >Rimuovi</a>
</div>
</td>
</tr>
</c:forEach>
</tbody>
paneltypeへのnull参照を取得するたびに。私は明らかに@InitBinder
コントローラーでを使用しました:
Initbinder
@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(Paneltype.class, "paneltype", new PropertyEditorSupport() {
@Override
public void setAsText(String text) {
int i=0;
PaneltypeDAO pDAO=new PaneltypeDAO();
setValue(pDAO.findById(Integer.parseInt(text)));
}
});
}
しかし、コードがこれに到達することはありません。これは、jspが値がであることを確認しているようなものですnull
。
提案?ありがとう