SpringMVC form:options items属性:究竟是什么期望? [英] SpringMVC form:options items attribute: what exactly is it expecting?
问题描述
我还是SpringMVC的新手(和jstl一样).我试图填充对象列表中的选择中的选项.我已经找到了一种使用c:forEach的方法,但是我一直在想有一种方法可以使form:options方法起作用.
I'm still new to SpringMVC (and jstl for that matter). I'm trying to populate options in a select from a list of objects. I've found a way to do it using c:forEach, but I keep thinking there HAS to be a way to make the form:options method work.
我已经浏览了一下,关于物品属性我可以找到的与官方文档最接近的地方是这里>>
I've browsed around, and about the closest thing I can find to official documentation on the items attribute is here >> http://static.springsource.org/spring/docs/2.0.x/reference/spring-form.tld.html#spring-form.tld.options
它表示items属性用于
It says the items attribute is for
用于生成内部'option'标签的对象的Collection,Map或数组"
"The Collection, Map or array of objects used to generate the inner 'option' tags"
我的困惑是正在寻找什么样的集合,地图或对象数组.他们需要采用什么格式?它是专门寻找String类型的Collection还是数组?我可以使用
My confusion is what kind of Collection, Map, or array of objects it's looking for. What format do they need to be in? Is it looking for a Collection or array of type String specifically? Can I use
List<MyObject>
,如果是这样,MyObject必须具有什么才能使其有效(即方法,变量)?
and if so, what would MyObject have to have in it in order for this to be valid (i.e. methods, variables)?
当前,当我尝试使用MyObject时,出现一个异常-
Currently, when I try to use MyObject, I get an exception that says -
ConverterNotFoundException:未找到能够从com.example.MyObject类型转换为java.lang.String类型的转换器
ConverterNotFoundException: No converter found capable of converting from type com.example.MyObject to type java.lang.String
我需要制造转换器吗?那会去哪里?那将如何工作?我已经搜索了该错误消息,但还没有真正找到我要尝试执行的操作...(大多数是有关Roo的结果)
Do I need to make a converter? Where would that go? How would that work? I've googled that error message and haven't really turned up anything specific to what I'm trying to do... (Most are results about Roo)
MyObject类如下:
the MyObject class looks like this:
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;
}
}
而我正试图将其用于此类目的:
and I'm trying to use it as such:
<form:select path="myObjectList">
<form:option value="0"/>
<form:options items="myObjectList" />
</form:select>
有人知道这种方法有什么不正确吗?或者,我应该使用
Does anyone know specifically what is incorrect about this method? Or, should I be using a
List<String>
完成我在做什么?
编辑,这是堆栈跟踪>> http://pastebin.com/2c5XBCmG
EDIT here's the stack trace >> http://pastebin.com/2c5XBCmG