Java Reference
In-Depth Information
More Select Box Features
Besides the <s:options-collection> tag, you can also use
<s:options-map> and <s:options-enumeration> to generate
options in a select box from a Map and an enum , respectively.
With <s:options-map>, the collection of values is the map's set
of Map.Entry objects, as obtained from entrySet ( ). For <s:options-
enumeration>, specify the enumeration in the enum= attribute
to generate options based on the values defined by the enu-
meration.
With all three <s:options-xx> tags, you can also use the group=
attribute to generate <optgroup/> tags within a select box. This
groups options together with a different label for each group.
For example, say the Folder class had a type property. With two
folders named Inbox and Reference having the Received type
and with two folders named Outbox and Archive having the Sent
type, you could use group="type" to group folders by their type:
<s:select name="selectedFolder">
<s:options-collection collection="${actionBean.folders}"
value="id" label="name" group="type"/>
</s:select>
This would generate a select box, as shown here:
Here's one more tip. If you have a collection of objects from
which you want to generate options in a select box but want to
display labels in different formats without polluting your model
class with formatting code, you can always implement a For-
matter with the different format types and patterns you need.
Then, you can generate the options with the plain <s:option>
tag and use <s:format> to format the label in different ways.
For example:
<s:select name="...">
<c:forEach items="${someCollection}" var="item">
<s:option value="${item.id}">
<s:format value="${item}" formatType="..." formatPattern="..."/>
</s:option>
</c:forEach>
</s:select>
 
 
Search WWH ::




Custom Search