Dear All,
I have 2 entities "Task" and "Employee" which has many to many relationship.
To assign employees for particular task I followed same thing that had done
for adding user roles for user.
List boxes populated well and I could move items back and forth. But I was
unable to save Employees related to task in DB as I could not get list of
values from action (TaskAction.java) class which is passes from
taskForm.jsp.
String[] emp = getRequest().getParameterValues("taskEmployees"); -> emp is
null
I appreciate your guidance on this and code segments are as follows.
taskForm.jsp
==========
<fieldset>
<legend><fmt:message key="task.assignEmployees"/></legend>
<table class="pickList">
<tr>
<th class="pickLabel">
<label class="required"><fmt:message
key="task.employees"/></label>
</th>
<td></td>
<th class="pickLabel">
<label class="required"><fmt:message
key="task.assignedEmployees"/></label>
</th>
</tr>
<c:set var="leftList" value="${availableEmployees}"
scope="request"/>
<s:set name="rightList" value="task.employeeList"
scope="request"/>
<c:import url="/WEB-INF/pages/pickList.jsp">
<c:param name="listCount" value="1"/>
<c:param name="leftId" value="availableEmployees"/>
<c:param name="rightId" value="taskEmployees"/>
</c:import>
</table>
</fieldset>
Task.java
=======
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name="employee_t_task_t",
joinColumns = { @JoinColumn( name="assignedTaskList_sid") },
inverseJoinColumns = @JoinColumn(
name="assignedEmployeeList_sid")
)
public Set<Employee> getEmployees() {
return employees;
}
public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
TaskAction.java
============
public String save() throws Exception {
///////////////Some code here
String[] emp = getRequest().getParameterValues("taskEmployees");
for (int i = 0; emp != null && i < emp.length; i++) {
String empName = emp[i];
task.addEmployee(employeeManager.findEmployeeByName(empName));
}
}
taskManager.save(task);
}
Regards
Bandula