java - thymeleaf attribute check contains by other attribute value -
my spring controller send object "department" , form , needs check how many jobs departments checked employee save works great when user edit employee needs see jobs checked.
to make work need make like: th:checked="${jobs.contains(${job.id})}" guess can't put attribute value inside other attribute value.
<div th:each="job : ${department.joblist}" class="col-md-4"> <fieldset class="form-group"> <label class="custom-control custom-checkbox"> <input name="jobs" th:checked="${jobs.contains(34l)}" th:value="${job.id}" type="checkbox" class="custom-control-input"/> <span th:text="${job.name}" class="custom-control-description"></span> <span class="custom-control-indicator"></span> </label> </fieldset> </div>
my controller:
// edit employee page @requestmapping("/panel/{workplacename}/employees/{id}") public string editemployeespage(model model, httpsession httpsession, httpservletrequest request,@pathvariable long id) { // auto login check workplace workplace = new workplace(); employee employee = new employee(); object logintemp = httpsession.getattribute ("loggedinuser"); if (logintemp != null){ object templogin = httpsession.getattribute ("loggedinuser"); login login = (login) templogin; workplace = workplaceservice.findbyid(login.getusername()); model.addattribute("workplace",workplace); employee = employeeservice.findbyid(id); if(!model.containsattribute("employee")) { model.addattribute("employee", employee); } } else { return "redirect:/"; } // end of auto login check arraylist<long> jobs = new arraylist<>(); (int = 0; < employee.getjoblist().size(); i++) { jobs.add(employee.getjoblist().get(i).getid()); } model.addattribute("jobs", jobs); model.addattribute("action","/panel/"+workplace.getname()+"/employees/"+employee.getid()); return "workplace/editemployee"; }
ok answer : th:checked="${jobs.contains(job.id)}"
my mistake was: th:checked="${jobs.contains(${job.id})}"
Comments
Post a Comment