2
votes

I am beginning with Thymeleaf. I just copied an example and adjusted it to my needs. However it does not work. I appreciate any help.

Label

@Entity 
public class Label {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "label_id")
private Long labelId;

private String label;

public Label() {
}

public Label(Long labelId, String label) {

    this.labelId = labelId;
    this.label = label;
}

public Label(String label) {

    this.labelId = null;
    this.label = label;
}


public Long getLabelId() {
    return labelId;
}

public void setLabelId(Long labelId) {
    this.labelId = labelId;
}

public String getLabel() {
    return label;
}

public void setLabel(String label) {
    this.label = label;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof Label)) return false;

    Label label1 = (Label) o;

    return getLabel().equals(label1.getLabel());
}

@Override
public int hashCode() {

    return Objects.hash(getLabel());
}

@Override
public String toString() {
    return "Label{" +
            "labelId=" + labelId +
            ", label='" + label + '\'' +
            '}';
} }

Controller

@Controller
public class LabelController {


private NoteHandler handler;

@Autowired
public LabelController(NoteHandler handler) {
    this.handler = handler;
}

@RequestMapping(value = "/savelabel", method = RequestMethod.GET)
public String showSaveLabelForm(Model model) {
    model.addAttribute("labelentity", new Label());
    return "labelform";
}

@RequestMapping(value = "/savelabel", method = RequestMethod.POST)
public String submitLabel(@ModelAttribute Label labelentity) {
    return "result";
}    }

labelform.html

> <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head>
>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>     <title>Save a New Label</title> </head> <body> <h1>Form</h1> 
><form action="#" th:action="@{/savelabel}" th:object="${labelentity}" method="post">
>     <p>Id: <input type="text" th:field="*{labelId}" /></p>
>     <p>Label: <input type="text" th:field="*{label}" /></p>
>     <p><input type="submit" value="Submit" /> <input type="reset" 
>value="Reset" /></p> </form> </body> </html>

result.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Saved Label</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Result</h1>
<p th:text="'id: ' + ${labelentity.labelId}" />
<p th:text="'label: ' + ${labelentity.label}" />
<a href="/savelabel">Save another label</a>
</body>
</html>

The problem: I go to labelform page, fill 1 into ID field, abc to label, I submit, it gives me error

There was an unexpected error (type=Bad Request, status=400). Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc"

I guess that label is incorrectly being bound to labelId. Why? Thanks for help.

The console output:

...

: Found resource handler mapping: URL pattern="/webjars/", locations=[class path resource [META-INF/resources/webjars/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@349312d5] 2017-12-29 14:58:30.488 DEBUG 5492 --- [ main] o.s.w.s.resource.ResourceUrlProvider : Found resource handler mapping: URL pattern="/", locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@5885e231] 2017-12-29 14:58:30.573 INFO 5492 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2017-12-29 14:58:30.574 DEBUG 5492 --- [ main] o.s.w.c.s.StandardServletEnvironment : Adding PropertySource 'server.ports' with highest search precedence 2017-12-29 14:58:30.579 INFO 5492 --- [ main] krystof.App
: Started App in 8.625 seconds (JVM running for 9.133) 2017-12-29 14:58:39.455 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing servlet 'dispatcherServlet' 2017-12-29 14:58:39.460 INFO 5492 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2017-12-29 14:58:39.460 INFO 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2017-12-29 14:58:39.460 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet
: Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@6ad6ae45] 2017-12-29 14:58:39.464 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@19ac22ef] 2017-12-29 14:58:39.477 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@2ba12e19] 2017-12-29 14:58:39.484 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@4aca5c03] 2017-12-29 14:58:39.493 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@6434e440] 2017-12-29 14:58:39.494 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet] 2017-12-29 14:58:39.494 INFO 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 34 ms 2017-12-29 14:58:39.494 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Servlet 'dispatcherServlet' configured successfully 2017-12-29 14:58:39.512 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/savelabel] 2017-12-29 14:58:39.517 DEBUG 5492 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /savelabel 2017-12-29 14:58:39.520 DEBUG 5492 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)] 2017-12-29 14:58:39.542 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin 2017-12-29 14:58:39.578 DEBUG 5492 --- [nio-8080-exec-2] .w.s.m.m.a.ServletInvocableHandlerMethod : Failed to resolve argument 0 of type 'krystof.business.Label'

org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:71) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:47) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:713) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttributeFromRequestValue(ServletModelAttributeMethodProcessor.java:137) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:75) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131] Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:43) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.data.repository.support.DomainClassConverter$ToEntityConverter.convert(DomainClassConverter.java:157) ~[spring-data-commons-1.13.9.RELEASE.jar:na] at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:108) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:64) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] ... 56 common frames omitted Caused by: java.lang.NumberFormatException: For input string: "abc" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_131] at java.lang.Long.parseLong(Long.java:589) ~[na:1.8.0_131] at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_131] at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:211) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:62) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:49) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService$ConverterFactoryAdapter.convert(GenericConversionService.java:436) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] ... 64 common frames omitted

2017-12-29 14:58:39.579 DEBUG 5492 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.581 DEBUG 5492 --- [nio-8080-exec-2] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.592 DEBUG 5492 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.593 WARN 5492 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to bind request element: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.593 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 2017-12-29 14:58:39.594 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Successfully completed request 2017-12-29 14:58:39.606 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/error] 2017-12-29 14:58:39.607 DEBUG 5492 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error 2017-12-29 14:58:39.610 DEBUG 5492 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)] 2017-12-29 14:58:39.611 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin 2017-12-29 14:58:39.638 DEBUG 5492 --- [nio-8080-exec-2] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, text/html;q=0.8] based on Accept header types and producible media types [text/html]) 2017-12-29 14:58:39.654 DEBUG 5492 --- [nio-8080-exec-2] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView@2b999ee8] based on requested media type 'text/html' 2017-12-29 14:58:39.654 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet
: Rendering view [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView@2b999ee8] in DispatcherServlet with name 'dispatcherServlet' 2017-12-29 14:58:39.694 DEBUG 5492 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Successfully completed request

1
Can you provide more of the stack trace please? One problem you will have is that in the model for the post request the label will be called label rather than labelentity. You can fix this by changing @ModelAttribute(name = "labelentity") but I'm not convinced this is the only problem from the error your describe.saml
@Sam I updated the question. Thanks for help.KrystofP
Did you fix the thing I mentioned above? Which version of spring?saml
@Sam I fixed it as you suggested and it works! Thanks very much. how can I upvote you?KrystofP
I'll repost as an answer :)saml

1 Answers

0
votes

It is a little unclear to me exactly why you see the error that you do since when I've tried your code I get

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'labelId' cannot be found on null

I suspect that the difference is down to some code you might have redacted in your listings.

However the issue is related to the fact that in your post request controller method you have the following @ModelAttribute Label labelentity, this means spring will have added an attribute with the name label to the model map, however your template refers to labelentity so you need to change this to be

@ModelAttribute(name = "labelentity")