Spring中的命令对象 [英] Command Objects in Spring

查看:107
本文介绍了Spring中的命令对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由原始字段和对象字段组成的命令对象。如何将表单字段绑定到对象中的字段?

I have a command object composed of primitive fields and an object field. How do I bind my form fields to the fields in the object?

我试过这样做但无济于事

I tried doing this but to no avail

<form:form commandName="course" method="POST">
     <form:input path="activity.activity"/>
         .
         .
         .
</form:form>

我收到此错误

org.springframework.beans.NotReadablePropertyException: 
      Invalid property 'course' of bean class

我的Command类是这样的

My Command class is like this

public class Course {
    private long id;
    private String owner;
    private String title;
    private List<LearningActivity> activity = new ArrayList<LearningActivity>();

    //getters and setters
}

public class LearningActivity {
private long ID;
private String activity;
    private String link;

    //getters and setters
}


推荐答案

您的列表需要预先填充您计划引用的LearningActivity对象(使用activity [0],activity [1]等),或者它需要是一个惰性列表。惰性列表是一个列表,当引用给定索引时,它将使用空对象填充自身。

Your list either needs to be pre-populated with as many LearningActivity objects as you plan to refer to (using activity[0], activity[1], etc.) or it needs to be a lazy list. A lazy list is a list that will populate itself with empty objects when a given index is referenced.

注释表明您正在尝试使用Apache Commons LazyList,应该工作 - 你错过了一个导入指令吗?但是,作为替代方案,有一个名为AutoPopulatingList的Spring惰性列表实现。

A comment indicates that you're trying to use Apache Commons LazyList, which ought to work -- are you missing an import directive? However, as an alternative there is a Spring lazy list implementation called AutoPopulatingList.

这篇关于Spring中的命令对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆