I have two combo- boxes and I want to get the values from the option selected in the first combo box and, the list is present in the class object which is to be selected in the first combo-box
E.g I have two Branches Accounts and Legislation Account has further two sub-branches: Finance,financial statement which are present in the Branch Object as a list
Legislation: Questions, Resolution
When the user selects the Account, the second combo box automatically loads the list in Account Object into the second combo-box
1st combo-box -- selected Account 2nd combo-box -- shows Finance, Financial Statement
<option />
<c:forEach items="${branchList}" var="branch">
<option value="${branch.branchName}">${branch.branchName}</option>
</c:forEach>
</select>
<td>Sub Branch</td>
<td> <select name="subBranchName" >
<c:forEach items="${subBranchList}" var="subBranch">
<option value="${subBranch.subBranchName}">${subBranch.subBranchName}</option>
</c:forEach>
</select> </td>
My Branch Class:
@Entity
@NamedQuery(name="Branch.findAll", query="SELECT b FROM Branch b")
public class Branch {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="BRANCH_ID")
private long branchId;
@Column(name="BRANCH_NAME")
private String branchName;
//bi-directional many-to-one association to EmployeeDetail
@OneToMany(mappedBy="branch")
private List<EmployeeDetail> employeeDetails;
//bi-directional many-to-one association to SubBranch
@OneToMany(mappedBy="branch")
private List<SubBranch> subBranches;
// Getters & Setters
My Controller:
@RequestMapping("createFile")
public ModelAndView createFile(@ModelAttribute Employee employee , Model model) {
List<Branch> branchList = branchService.getList();
model.addAttribute("branchList", branchList);
ArrayList<String> documentType = new ArrayList<String>();
documentType.add("PUC");
documentType.add("Annex");
model.addAttribute("documentType", documentType);
String notings = " ";
model.addAttribute("notings", notings);
logger.info("branch : "+branchList.get(1).getBranchName());
List<SubBranch> subBranchList = new ArrayList<SubBranch>();
subBranchList = subBranchService.getList();
model.addAttribute("subBranchList", subBranchList);
List<EmployeeDetail> employeeDetailList = employeeDetailService.getList();
model.addAttribute("employeeDetailList", employeeDetailList);
MultipartFile file = null ;
model.addAttribute("fileUpload", file);
return new ModelAndView("createNewFile");
}
The code is working fine when I load the sub-Branches list separately, but I want to load the list of Sub-Branches from the value of Branches i-e when a branch is selected the program automatically loads the list of sub-branches, the list of sub-branches is present in the Branch class that is the value I want to load into the sub-Branch list
I am new at Spring MVC and don't know how to load the values without invoking the controller.
Thanks in advance