0

在我的场景中,我在 JSP 上开发嵌套选择,绑定到一个 bean:

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(请注意这是在a中)

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

每次我得到一个对面板类型的空引用。我显然@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.

建议?谢谢

4

1 回答 1

0

我认为当您尝试提交此表单并且未在模型中获取绑定值时,您的问题仍然存在。

尝试使用LazyList初始化您的列表。请替换 PanelsBean 类中的面板声明,如下所示。

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

希望这对您有所帮助。干杯。

于 2012-06-11T09:17:17.507 回答