I am trying to achieve below process in thymeleaf ( I am new to thymeleaf ) 1. Import csv file and display to user 2. After displaying data to user , User will have option to update those data in DB
Currently I am facing issue while passing table object to controller class
GET
@RequestMapping(value = "/samplepage", method = RequestMethod.GET)
public String bulkupload(Model model, HttpSession session) {
AccountService wlaccservice = new AccountService();
//ArrayList<AccountService> accountentry = new ArrayList<AccountService>();
Accounts accountentry = new Accounts();
model.addAttribute("accountentry", accountentry.getAccountentry());
return "samplepage";
}
HTML (samplepage)
<tr class="table-row" th:each="account : ${accountentry}">
<td class="table-data" th:text="${account.accountnumber}"></td>
<td class="table-data" th:text="${account.noofilc}"></td>
I have Form with button imporing CSV file and Update DB button
Setter and Getter class public AccountService {
private String accountnumber,noofilc;
public String getAccountnumber() {
return accountnumber;
}
public void setAccountnumber(String accountnumber) {
this.accountnumber = accountnumber;
}
public String getNoofilc() {
return noofilc;
}
.....
}
Array Class
public class Accounts {
public ArrayList<AccountService> accountentry;
public ArrayList<AccountService> getAccountentry() {
return accountentry;
}
public void setAccountentry(ArrayList<AccountService> accountentry) {
this.accountentry = accountentry;
}
}
POST
@RequestMapping(value = "/samplepage", method = RequestMethod.POST)
public String bulkuploadPost(Model model,
@ModelAttribute("samplepage") AccountService acctservice,
@ModelAttribute Accounts accountentry,
HttpSession session, @RequestParam("file") MultipartFile file,HttpServletRequest request) {
String action = request.getParameter("action");
try {
if (action.equalsIgnoreCase("Import CSV")) // This part to load data into html table accountentry which is work fine
{
byte[] bytes= file.getBytes();
ByteArrayInputStream inputFilestream = new ByteArrayInputStream(bytes);
BufferedReader br = new BufferedReader(new InputStreamReader(inputFilestream));
String line = "";
ArrayList<AccountService> arraylist = new ArrayList<AccountService>();
while ((line = br.readLine()) != null) {
TypeWhiteListAccountDetails accountDetails = new TypeWhiteListAccountDetails();
accountDetails.Tablebulkupdate(line,arraylist); //getting array from here to load it in accountentry variable
}
br.close();
accountentry.setAccountentry(arraylist);
model.addAttribute("accountentry", accountentry.getAccountentry());
}
else if (action.equalsIgnoreCase("Start Update")) // after I am having data in accountentry start calling data from html to load in DB
{
model.addAttribute("accountentry", accountentry);
System.out.println(accountentry.getAccountentry()); // always am getting as null for attribute accountentry
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "samplepage";
}
I am always getting null value for the line which I mentioned above in comment,please help me on this part