我对 SpringMVC (以及 jstl 来说)还是个新手。我正在尝试填充从对象列表中选择的选项。我找到了一种使用 c:forEach 来做到这一点的方法,但我一直认为必须有一种方法可以使 form:options 方法起作用。
我浏览了一下,我能找到的关于 items 属性的官方文档最接近的内容在这里 >>http://static.springsource.org/spring/docs/2.0.x/reference/spring-form.tld.html#spring-form.tld.options http://static.springsource.org/spring/docs/2.0.x/reference/spring-form.tld.html#spring-form.tld.options
它说 items 属性用于
“用于生成内部‘选项’标签的对象的集合、映射或数组”
我的困惑是它正在寻找什么样的集合、映射或对象数组。它们需要采用什么格式?它是专门寻找 String 类型的 Collection 或数组吗?我可以用吗
List<MyObject>
如果是这样,MyObject 必须包含什么才能使其有效(即方法、变量)?
目前,当我尝试使用 MyObject 时,我收到一个异常:
ConverterNotFoundException:找不到能够从 com.example.MyObject 类型转换为 java.lang.String 类型的转换器
我需要制作转换器吗?那会去哪里?那会如何运作呢?我已经用谷歌搜索了该错误消息,但并没有真正找到任何特定于我想要做的事情......(大多数是关于 Roo 的结果)
MyObject 类如下所示:
public class MyObject{
private String company;
private Customer customer;
private Address customerAddress;
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Address getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(Address customerAddress) {
this.customerAddress = customerAddress;
}
}
我正在尝试这样使用它:
<form:select path="myObjectList">
<form:option value="0"/>
<form:options items="myObjectList" />
</form:select>
有谁知道这个方法有什么不正确的地方吗?或者,我应该使用
List<String>
完成我正在做的事情?
EDIT这是堆栈跟踪>>http://pastebin.com/2c5XBCmG http://pastebin.com/2c5XBCmG