EDITED: I tried asking this in another question, since I felt that the originally asked question was sufficiently answered. I got chastised for doing that. So I've edited this question accordingly. Basically, I don't know the right syntax to access the properties of the List of Employees that are in the "value" of each Map entry.
I have a TreeMap stored in session variable. The "key" of the TreeMap holds a String. The "value" of the holds a List of Objects. The TreeMap is populated in the Action class. A sample TreeMap might look like this:
ArrayList<Employee> employeeList1 = new ArrayList<Employee>();
Employee myEmployee = new Employee();
myEmployee.setEmployeeId("123");
myEmployee.setEmployeeName("John Doe");
employeeList1.add(myEmployee);
myEmployee = new Employee();
myEmployee.setEmployeeId("456");
myEmployee.setEmployeeName("Jane Doe");
employeeList1.add(myEmployee);
...
TreeMap<String,Employee> availableSupervisorsMap = new TreeMap<String,Employee>();
availableSupervisorsMap.put("A", employeeList1);
availableSupervisorsMap.put("B", employeeList2);
availableSupervisorsMap.put("C", employeeList3);
session.setAttribute("availableSupervisorsMap", availableSupervisorsMap);
In the JSP, I want to show a select box with each "key" as an optgroup label, and each employeeId and employeeName in the "value"'s list of Employee objects as the option value and display, respectively. I tried the code below, to no avail:
<s:select name="availableIds" list="%{#session.availableSupervisorsMap}" multiple="true">
<s:optgroup label="%{key}">
<s:iterator value="%{value}">
<option value="<s:property value="employeeId"/>">
<s:property value="employeeName"/>
</option>
</s:iterator>
</s:optgroup>
</s:select>
So the select box SHOULD look something like this, minus the bullet points of course:
when I try the JSP code above, the following HTML is generated:
<select name="availableIds" id="AssignmentSupervisors_availableIds" multiple="multiple">
<option value="A">[Employee:
=========================================================
employeeName = John Doe
employeeId = 123
=========================================================
, Employee:
=========================================================
employeeName = Jane Doe
employeeId = 456
]</option>
<optgroup
>
I have verified that the map is populated exactly as I expect it to be. So it's making it to the JSP with the correct data.
%{}
with #
and #{}
(three different things);var
keyword;The correct code is easier than you think:
<s:select name="availableIds" list="%{#session.availableSupervisorsMap}" multiple="true">
<s:optgroup label="key">
<s:iterator value="value" var="currentRow">
<option value="%{#currentRow.employeeId}">
<s:property value="%{#currentRow.employeeName}"/>
</option>
</s:iterator>
</s:optgroup>
</s:select>