2012-06-11 80 views
0

我的方案,我開發嵌套選擇一個JSP,綁定到一個bean:春3 MVC嵌套形式:選擇

public class WizardPanelp1Bean { 

private Integer id; 
private Stringofpanels stringofpanels; 
private Paneltype paneltype; 
private Integer number; 
private String paneltypestring; 
//and getters/setters... [Omitted] 

現在我有Paneltype對象,另一個簡單的bean

Paneltype

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 面板

public class PanelsBean { 
    private ArrayList<WizardPanelp1Bean> panels =new ArrayList<WizardPanelp1Bean>(); 

,最後我去JSP的一個簡單的ArrayList(請注意,這是一個)

<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的空引用。我明明在控制器上使用的@InitBinderInitbinder

@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

對此提出建議?謝謝

+0

我想我錯過了名字=「」之後但現在我無法綁定結果 – Gtazok

回答

0

我認爲當您嘗試提交此表單並且未在模型中獲取綁定值時,您的問題仍然存在。

嘗試初始化您的列表使用LazyList。請在PanelsBean類中替換您的面板聲明,如下所示。

private List<WizardPanelp1Bean> panels = LazyList.decorate(new ArrayList<WizardPanelp1Bean>(),FactoryUtils.instantiateFactory(WizardPanelp1Bean.class)); 

希望這可以幫助你。乾杯。