Exception evaluating SpringEL expression: "#dates.format(passation.datepassation, 'dd-MMM-yyyy')"

the bignner

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!

vphilipnyc

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.

edited at
0

Comments

0 comments
Login to comment

Related

Exception evaluating SpringEL expression, spring guru course

how to resolve this : Exception evaluating SpringEL expression: "#authorization.expression('isAuthenticated()')"?

Exception evaluating SpringEL with Spring MVC

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "ServiceAmc.id" (results:30)

"Exception evaluating SpringEL expression" error while trying to iterate List(<Object>) in Thymeleaf Spring Boot

How to fix "Exception evaluating SpringEL expression" error after submitting a variable Spring/Thymeleaf

Thymeleaf: "Exception evaluating OGNL expression" in a simple for loop

erlang: exception error when evaluating an arithmetic expression

Evaluating an if expression behaves differently then evaluating a BOOL expression

Evaluating an expression in gekko

Evaluating Expression Tree

Evaluating call expression

evaluating statement cin==(expression)

Evaluating a mathematical expression in a string

CASE expression in MySQL not evaluating

Evaluating JavaScript expression with a worker

Evaluating an Expression using MVEL

Evaluating Expression in Function call

XPath expression not evaluating

Evaluating mathematical expression in R

Angular JS expression not evaluating

Ternary generator expression not evaluating

Evaluating expression in Lua in an Environment

Evaluating boolean expression with recursive

Evaluating a postfix expression

ng-if expression evaluating incorrectly

Evaluating the expression 1 <= month <= 12

Evaluating expression inside angular directive

Evaluating a switch expression at runtime in C