How can I use a List of object with the Stripes option tag?

I have a list of objects created by JPA q.getResultList() .

I would like to use it in a drop-down list, but the Stripes option tag cannot accept List, just Collection , Enum and Map .

I am new to Java, so maybe List can translate to each of them, but I don’t know how I can solve this problem.

(Selecting Stripes, option-map, -enumeration, -collection can create a fall from previous structures of input objects)

+4
source share
2 answers

The documentation for the options-collection tag reads:

Writes a set of <option value="foo">bar</option> tags to pages based on the contents of the Collection , Iterable or Array . each item in the collection is represented by one option tag per page. Uses the label and value attributes in the tag to name the properties of the objects in the Collection , which should be used to generate the body of the HTML tag option and the value attribute of the HTML tag, respectively. If either (or both) labels or property values ​​are omitted itself will be used for label / value instead - this is done to support collections of simple types like strings and numbers.

eg. tag declaration that looks like:

 <stripes:options-collection collection="${cats}" value="catId" label="name"/> 

will cause the container to search for a Collection , called "cats", through various areas of the JSP and set it to a tag. Then the tag will iterate over this collection by calling getCatId() and getName() on each cat creates HTML tags.

A java.util.List being a Collection , just pass it to the Collection attribute of the specified tag.

+4
source

A List object is a Collection object: the List interface extends the Collection interface. You can use a List object, such as an ArrayList or LinkedList , wherever you need a Collection .

The Enum type is a kind of static list, declaring the class as enum, for example:

 public enum MyEnum { FirstOption, SecondOption, ThirdOption; } 

The type Map is an associative set; e.g. Hashtable , HashMap and TreeMap are all instances of a Map .

+1
source

Source: https://habr.com/ru/post/1305325/


All Articles