问题
I want to display the key value bean based on sorting of value in Struts 2.
<s:select list="preferredBranchList" listKey="displayKey"
listValue="displayValue" name="preferredBranch"
cssClass="selectpicker show-tick" required="true" />
its sorting the values based on listKey
. please suggest me to sort the values based on listValue
.
回答1:
You can try and sort the values in Action class itself, so when select is rendered the list will appear sorted
回答2:
The List
is an ordered collection. If it contains elements sorted by the key property then other the value property remains unsorted unless it's the same property. To make it sorted on another property you can sort the list with the comparator.
Collections.sort(myList, myComparator);
or you can use s:sort
tag like in this example. And you only have to provide the comparator in the action class.
来源:https://stackoverflow.com/questions/31156860/i-want-to-display-the-key-value-bean-based-on-sorting-of-value-in-struts-2