I have a List of object, produced by JPA q.getResultList()
.
I would like to use it in a drop down, but Stripes "option" tag cant accept List, just Collection
, Enum
and
Map
.
Im new to Java, that why perhaps the List
can translated to each of them but I don't know ho开发者_运维知识库w can I solve this issue.
(Stripes select,option-map,-enumeration, -collection can build up a drop down from previous mentioned input object structures )
The documentation of the options-collection tag says:
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
being a Collection
, just pass it to the collection
attribute of the mentioned tag.
A List
object is a Collection
object: the the List
interface extends that of Collection
. You can use a List
object, such as ArrayList
or LinkedList
in all places where you need a Collection
.
The Enum
type is a sort of static list, by declaring a class as being an enum, like so:
public enum MyEnum {
FirstOption, SecondOption, ThirdOption;
}
The Map
type is an associative set; e.g. the Hashtable
, HashMap
and TreeMap
are all instances of a Map
.
精彩评论