tags:

views:

348

answers:

2

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 how can I solve this issue.

(Stripes select,option-map,-enumeration, -collection can build up a drop down from previous mentioned input object structures )

+1  A: 

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.

Pindatjuh
Thanks for the quick reply, naturally I have used a List of object for a probe. It doesnt work for me. I believe your experience, so the error is in my side.(something wrong in using list)
+2  A: 

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 a Collection, Iterable or Array. 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 the Collection 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 calling getCatId() and getName() 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.

Pascal Thivent
thanks for the quick reply, i have tried a list (on the analogy of help and your example), it doesnt work for me.but im sure, it made something wrongly.thanks the quick reply and the effort.
@cscsaba242 You're welcome. But without seeing your code, I'm afraid I won't be able to provide more help.
Pascal Thivent