I want to add date but i had this error when i save my form Exception evaluating SpringEL expression: "#dates.format(passation.datepassation, 'dd-MMM-yyyy')"
1-Thymeleaf:
`<label>Date:</label>
<label
th:object="${passation}"
th:value="${#dates.format(passation.datepassation, 'dd-MMM-yyyy')}" ></label>
2- class Passation
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date datepassation;
3-in controller:
@Autowired(required=true)
private PassationRepository passationRepository;
@RequestMapping(value="/passation",method=RequestMethod.GET)
public String passation(Model model){
List<Passation> passations=passationRepository.findAll();
model.addAttribute("listPassations",passations);
model.addAttribute("Date",new Date()); //add new date
return "passation";
}
` any help is appreciated, thanks!
Your variable passation
is null. So however you're creating the bean, make sure that passation
is not null and datepassation
is set on the bean.
@Autowired
private PassationRepository passationRepository;
@GetMapping("/passation") //note shorthand
public String passation(Model model) {
List<Passation> passations = passationRepository.findAll();
model.addAttribute("listPassations", passations);
// This should be in your service layer. Example only:
Passation passation = new Passation();
passation.setDatepassation(new Date());
//make sure the model has the bean
model.addAttribute("passation", passation);
return "passation";
}
This HTML will print the value from the bean.
<label>Date:</label>
<span th:text="${#dates.format(passation.datepassation, 'dd-MMM-yyyy')}">No date found</span>
If you're looking to update the bean values, use th:object
within a <form>
tag.
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments