Exception evaluating SpringEL with Spring MVC

user7589807

i start to use Spring MVC and i have a trouble. I want to get the value of a hashmap with the key. The object ProtoStatus contains a hashmap who i want to get value. I have this error :

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "protoStatus.status.get(30000)" (template: "protoStatusPage" - line 18, col 21)

public class ProtoStatus
{
    public HashMap<String, String> status;

    public void computeStatus()
    {
        this.status = new HashMap();

        for (int i=30000; i<30032; i++)
        {
            this.status.put(String.valueOf(i), String.valueOf(ServerChecker.Check("192.168.0.1", i)));
        }
    }

    public void setStatus(HashMap status)
    {
        this.status = status;
    }

    public HashMap getStatus()
    {
        return this.status;
    }

    public String getStatus(int key)
    {
        return (String) this.status.get(key);
    }
}

The Spring MVC part :

@PostMapping("/")
    public String submit(@ModelAttribute User user, @ModelAttribute ProtoStatus protoStatus)
    {
            protoStatus = new ProtoStatus();
            protoStatus.computeStatus();
            return "protoStatusPage";
    }

And Finaly, in the template protoStatusPage.html, i want to get the value for key 30000:

<p th:text="${protoStatus.status.get(30000)}" />
JB Nizet

Your status attribute is null by default. It only becomes non-null when you call computeStatus(). But you're never calling it on the ProtoStatus used by the view:

        protoStatus = new ProtoStatus();
        protoStatus.computeStatus();

Instead, you create a different one, and call computeStatus() on that one, that is then immediately eligible to garbage collection.

Also, you have a Map<String, String>, but your getStatus() method, and the expression in your view, tries to get something out of it usig a key of type Integer. That will always return null.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring MVC SseEmitter - connection aborted Exception

Spring MVC returning JSONS and exception Handling

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

doThrow Exception not throwing for spring MVC unit test?

Null Pointer Exception in Spring MVC Project

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

Exception unable to validate certificate of the target in spring MVC

Exception while starting spring web mvc application

Spring MVC jackson exception handling

Empty Exception Body in Spring MVC Test

No exception found but mail not send in Spring MVC

How to Disable Spring's "typeMismatch" Exception? - Spring MVC

Handling exception on Spring MVC Controller

Exception evaluating SpringEL expression, spring guru course

Serializable exception in spring mvc application

Spring MVC - Displaying Exception in View (JSP Page)

Spring MVC and Websocket Exception using Sockjs with Stompjs

Spring MVC Generic Exception Handling

Exception while evaluating service stack text for iOS

Qweb exception while evaluating in odoo report

Spring MVC: correct exception handling

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

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

Bean Creation Exception in Spring-MVC

Spring Mvc: An exception occurred processing JSP page

Class Cast Exception - Hibernate mapping + Spring MVC

Ajax POST FormData throw exception in Spring MVC

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

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