Struts 2 provides a lot of useful tags that you can use in your jsp pages, to help simplify your html/java code.
One in particular that is fairly complex and requires explanation is the <select> tag.
Typical html select tags require you to specify the list of values one by one, creating potentially lengthy code. It's relatively inflexible and workarounds are usually abundant to get it to behave how you want.
The Struts 2 <s:select> tag however, provides nearly everything you could need to have fully functioning select dropdown functionality.
The attributes I use are headerKey, headerValue, list, listValue, and listKey.
One by one, headerValue allows you to tell your dropdown to initially display a message to your user. For example, if you want to tell your user, "Please select an employee", you can simply use that as the headerValue, and that will display as the very first option in your dropdown list.
The headerKey attribute assigns a value to the headerValue attribute. My headerKey is typically -1. Using this, when a page is submitted, I can easily ensure that a legitimate value has been selected, by ensuring the headerKey != -1.
list, tells the Struts tag what variable contains the list that you want to appear in the dropdown. The value you use for the list attribute must be iterable. In my Java action, I provide an ArrayList object that contains the values I want to be in my dropdown list. So if I have an Employee object, with getters and setters for employeeId and employeeName, and within my ArrayList called employeeList that has my Employee objects, I can specify that my list attribute is employeeList.
Next up is the listValue and listKey attributes. They work together. The listValue is what actually gets displayed in the dropdown list. Not the list that is iterated over, but the actual words themselves that appear. So using the employee example, I'd want the user to see the names of employees in my dropdown, so I'd specify my listValue="employeeName".
The listKey attribute indicates what request parameter value should be passed back to my action upon submission. For this example I'd make listKey="employeeId". But if you wanted to pass the name that was selected, you'd simply make listKey="employeeName".
Apart from the basic name and value attributes, which are self explanatory, you now have a fully functional dropdown list in your jsp, simply by using:
<s:select name="myEmployee" list="employeeList" headerKey="-1" headerValue="Please Select an Employee" listValue="employeeName" listKey="employeeId" />
And there you have it. The power of the Struts 2 <s:select> tag semi-de-mystified.