我有一个对象列表,由 JPA q.getResultList()
生成。
我想在下拉列表中使用它,但 Stripes“选项”标签不能接受列表,只能接受 Collection
、Enum
和
map
。
我是 Java 的新手,这就是为什么 List
可以翻译成它们中的每一个,但我不知道如何解决这个问题。
(Stripes select、option-map、-enumeration、-collection 可以从前面提到的输入对象结构中构建下拉列表)
最佳答案
的文档 options-collection 标签说:
Writes a set of
<option value="foo">bar</option>
tags to the page based on the contents of aCollection
,Iterable
orArray
. Each element in the collection is represented by a single option tag on the page. Uses the label and value attributes on the tag to name the properties of the objects in theCollection
that should be used to generate the body of the HTML option tag and the value attribute of the HTML option tag respectively. If either (or both) of the label or value properties are omitted the item itself will be used for the label/value instead - this is done to support collections of simple types like Strings and Numbers.E.g. a tag declaration that looks like:
<stripes:options-collection collection="${cats}" value="catId" label="name"/>
would cause the container to look for a
Collection
called "cats" across the various JSP scopes and set it on the tag. The tag would then proceed to iterate through that collection callinggetCatId()
andgetName()
on each cat to produce HTML option tags.
A java.util.List
是一个 Collection
,只需将其传递给 collection
提到的标签的属性。
关于java - 如何使用带有 Stripes "option"标签的对象列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2531072/