2012-06-11 117 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)); 

希望这可以帮助你。干杯。