How to fix: Exception evaluating SpringEL expression

I am trying to save an “employee” model without assigning any “phone” model to it (oneToOne relationship). I have a form, in which i create the employee by adding: firstName, lastName and then a dropdown list from where i can select a phone to assign it. Whenever i do not select anything, the index.html page throws: Exception evaluating SpringEL expression: “ +’ ‘+” (template: “index” – line 31, col 17)

<div align="center">
<table >
        <th>Id Employee</th>
        <th>Last Name</th>
        <th>First Name</th>
    <tr th:each="employee: ${employeeList} ">
        <td th:text="${}">Id</td>
        <td th:text="${employee.lastName}">Last Name</td>
        <td th:text="${employee.firstName}">First Name</td>
        <td th:text="${ +' '+} ">Brand</td>
            <a th:href="@{'employee/edit/' + ${}}"><button class="btnEdit"><i class="fa fa-edit"></i></button></a>
            &nbsp &nbsp
            <a th:href="@{'employee/delete/' + ${}}"><button class="btnDelete"><i class="fa fa-edit"></i></button></a>

I mention that the object can be found in DB and the phone_id is null. I want to add some employees with a phone and some without any phone.
The output should be:
Doe John noPhone -> nothing selected from dropdown list.
Doe Jane iPhone 10s – > phone selected.

Do you have any suggestions ?

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

If phone can be null, try to use null-safe accessor ?.. Try something like this