• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Springboot Thymeleaf NOT rendering templates under src/main/resources/templates

 
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
In initial phases of learning Spring,SpringBoot + its respective web framework MVC .. Springboot Thymeleaf NOT rendering templates under src/main/resources/templates

MVC: 1 Controller portion of source code:


1 View Portion of Source Code:



Respective Configuration Class:


BUT when pointing to http://localhost:8090/design: renders String object "design"...... NOT the respective Spring Thymeleaf template..as a check on the GET request handling method it is returning the respective Model objects..
 
Saloon Keeper
Posts: 15608
366
  • Number of slices to send:
    Optional 'thank-you' note:
Welcome to CodeRanch!


You don't need any of the code in the Config class. Get rid of it.


Your problem is caused by wrong use of the annotations on your controller class. It should look like this:


The @Controller and @RequestMapping annotations should be on the controller class itself, not on the showDesignForm() method.

Don't put @ResponseBody on your controller action unless you want the return value to be interpreted as the actual HTTP response body. This is why your page displays the text "design", instead of forwarding the request to the design view.

In fact, you need never use @ResponseBody at all. If you want your controllers to return a JSON response body, create a separate controller for your web API and annotate it with @RestController instead of @Controller. This annotation implies that every action will behave as if you annotated it with @ResponseBody.

Finally, don't annotate the design parameter of the processDesign() action with @RequestBody. This will prevent your application from interpreting the submitted form correctly. Use @RequestBody only when your request body is something other than a HTML Form.
 
Partha Ray
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
the results when :
1) @ResponseBody is omitted
HTTP Status 500 – Internal Server Error

Type Exception Report

Message Request processing failed: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/design.html]")

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

jakarta.servlet.ServletException: Request processing failed: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/design.html]")
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1019)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100


2) AND Config.java file is omitted
Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Mar 26 11:06:01 EDT 2024
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template [design], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [design], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1103) ...




AND THANKS MUCH!
 
Stephan van Hulst
Saloon Keeper
Posts: 15608
366
  • Number of slices to send:
    Optional 'thank-you' note:
You're welcome.

Please show us your pom.xml file.
 
Partha Ray
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
When i attempt to paste in respective  xml source code with ... says sorry post is spam...also unable to attach xml file... thinking how to share xml file???

 
Marshal
Posts: 4525
572
  • Number of slices to send:
    Optional 'thank-you' note:
Posting the contents of the pom.xml file on Partha Roy's behalf:
 
Partha Ray
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
Root Cause

java.io.FileNotFoundException: class path resource [templates/design.html] cannot be opened because it does not exist
org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211)
org.thymeleaf.spring6.templateresource.SpringResourceTemplateResource.reader(SpringResourceTemplateResource.java:103)
org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:223)
org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1103)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1077)
org.thymeleaf.spring6.view.ThymeleafView.renderFragment(ThymeleafView.java:372)
org.thymeleaf.spring6.view.ThymeleafView.render(ThymeleafView.java:192)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1415)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1159)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1098)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:974)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)


AND this is the bottom of STACK root cause when ONLY @ResponseBody omitted

src/main/resources/templates -> home.html. "design" is logical name for the view rendered with respective thymeleaf.
 
Partha Ray
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
Root Cause

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'id' cannot be found on object of type 'com.example.demo.DomainTacoIngredient' - maybe not public or not valid?
org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:222)

so after i added design.html(identical to home.html) in addition to home.html... i get field property error
 
Stephan van Hulst
Saloon Keeper
Posts: 15608
366
  • Number of slices to send:
    Optional 'thank-you' note:
Right, the view name that you return from your controller action must match the name of the template file. Otherwise, Spring wouldn't know which template to load.

Duplicating your views doesn't make sense. Either name your template "home" and return "home" from the controller, or name the template "design" and return "design" from the controller.

All the properties that you use in your template must be public. You should make your DomainTacoIngredient and your DomainTacoDesign classes public, and their properties as well.
 
Partha Ray
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
why do the data/properties/ fields HAVE to be public ? Is it not good practice to keep data private vs functionality public??
when i do make the data private.. then i get this stack trace error at bottom of stack:
Root Cause

org.springframework.beans.NotReadablePropertyException: Invalid property 'name' of bean class [com.example.demo.DomainTacoDesign]: Bean property 'name' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:626)
 
Stephan van Hulst
Saloon Keeper
Posts: 15608
366
  • Number of slices to send:
    Optional 'thank-you' note:
You're right, it IS good practice to keep things as private as possible.

Key phrase being "as possible".

The the entire purpose of your bean is to make the properties available to the template processor. Properties that are private are not available to the template processor.

Try this:

If that doesn't work, make both the class and the getName() method public.

If you're also using your class to get data from the submitted form (which you appear to be), then use this instead:

Again, if it complains about visibility, make the class itself, the parameterless constructor, and the getter and the setter public.
 
Partha Ray
Greenhorn
Posts: 8
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
Thank you ALL for your diagnostic help! Any other conceptual issues  moving forward as i am sure there will be will reach out . Thanks!
 
Partha Ray
Greenhorn
Posts: 8
  • Number of slices to send:
    Optional 'thank-you' note:
Another concept issue... when checking application logs (logback).. the objects' field data are coming back as null even though filled out in form..









logger3 the name field, state field.. etc are null even though filled out



<form method="POST" th:action="@{/orders}" th:object="${order}">
<h1>Order your taco creations!</h1>
<img th:src="http://www.pmsas.pr.gov.br/wp-content/?id=coderanch-1z0-809&exam=@{/images/TacoCloud.png}"/>
<a th:href="http://www.pmsas.pr.gov.br/wp-content/?id=coderanch-1z0-809&exam=@{/design}" id="another">Design another taco</a><br/>
<div th:if="${#fields.hasErrors()}">
<span class="validationError">
Please correct the problems below and resubmit.
</span>
</div>

<h3>Deliver my taco masterpieces to...</h3>
<label for="name">Name: </label>
<input type="text" th:field="*{name}"/>
<br/>

<label for="street">Street address: </label>
<input type="text" th:field="*{street}"/>
<br/>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |