Reputation: 1139
I have the following enum
public enum AccountType {
ADMIN,
MANAGER
}
Now, in my Struts form I have the following tag:
<s:select name="account.accountType" list="{'ADMIN', 'MANAGER'}" />
This will generate the following field.
Is there any way to make it generate Administrator instead of ADMIN and Manager instead of MANAGER without editing the enum on the backend?
Upvotes: 3
Views: 1756
Reputation: 24396
In S2 instead of hard-coding your enum values into list in a JSP you can directly retrieve values from the enum itself using @package.Enum@values()
notation. And use listValue
attribute to show whatever you want based on some conditions.
For example:
<s:select name="account.accountType" list="@com.AccountType@values()"
listValue="top == @com.AccountType@ADMIN ? 'Administrator' : top" />
Upvotes: 4