I have a page will show a table of data(from database) on start and I am creating multiple fields for searching/filtering purpose.
My controller:
@RequestMapping(value = "/country", method = RequestMethod.GET)
public ModelAndView getCountryList(Model model) {
List<Country> countryList = countryService.getCountryList();
model.addAttribute("dateTime", todayDate());
model.addAttribute("pageTitle", "<a href=\"/pgwrefund\" />COUNTRY</a>");
return new ModelAndView("country", "countryList", countryList);
}
@RequestMapping(value="/filterCountry")
public ModelAndView getFilteredCountryList(@RequestParam String countrycode,@RequestParam String countryname,Model model){
List<Country> filteredCountryList = countryService.getFilteredCountryList(countrycode, countryname);
model.addAttribute("dateTime", todayDate());
model.addAttribute("pageTitle", "<a href=\"/pgwrefund\" />COUNTRY</a>");
System.out.println("List country:"+filteredCountryList.size() +"\nValue:"+ filteredCountryList);
return new ModelAndView("countrytemplate","filteredCountryList",filteredCountryList);
}
My View
<tbody>
<c:forEach var="country" items="${countryList}" varStatus="loopStatus">
<tr class="tbodydata ${loopStatus.index % 2 == 0 ? 'even' : 'odd'}">
<td>${country.countryCode}</td>
<td>${country.countryName}</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</c:forEach>
</tbody>
My filtered table view:
<c:forEach var="country" items="${filteredCountryList}" varStatus="loopStatus">
<tr class="tbodydata ${loopStatus.index % 2 == 0 ? 'even' : 'odd'}">
<td class="firsttd">${country.countryCode}</td>
<td class="secondtd">${country.countryName}</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</c:forEach>
So now, What I have done here is, first the i enter values to all the field and filter. The view pass the values to controller and it will filter using a query and return back to the view BUT with another table(foreach). Basically, I am replacing the filtered data with the original data. Then problems came up, most of the functions wont work including update and delete. My goal is, my country page able to filter the table data and stay at the same page. Any help will be appreciated.