How can I solve the problem with my multiple layouts in Thymleaf?
I m getting an error when i want to introduce another fragment from one layout page that contains to fragments. The one is for the header and the other for a post form. When i include just the first one I m getting a problem but if I add the other one i m getting two errors.
The first one is:
Error during execution of processor 'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor' (template: "fragments/header" - line 38, col 26)
The second one is
` ERROR 13400 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]
: Servlet.service() for servlet [dispatcherServlet] in context with path
[/api] threw exception [Request processing failed; nested exception is
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution
of processor
'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor'
(template: "fragments/header" - line 38, col 26)] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target
object for bean name 'tweet' available as request attribute`
The first fragment is a navigation bar and the second is post form. I was using thymleaf and spring boot.
The header.html is:
<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
...
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#"><strong>Twitter</strong></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li th:classappend="$module == 'home' ? 'active' : ''">
<a href="#" th:href="@/">My tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/new">Create a User</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/tweets">Tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/all">Display all Users</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/overview">Profile overview</a>
</li>
</ul>
</div>
</div>
</div>
<div th:fragment="post">
<!--/*@thymesVar id="tweet"
type="com.javalanguagezone.interviewtwitter.domain.Tweet"*/-->
<form th:action="@/tweets/" th:object="$tweet" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening?
Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>
The html file where i m calling the layout fragments looks like this:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8">
<title>User overview</title>
</head>
<body>
<div th:replace="fragments/header :: header"></div>
<div th:replace="fragments/header :: post"></div>
<div class="container-fluid" style="margin-top: 80px">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">User profile overview</h1>
</div>
<div class="panel-body">
<div class="table-responsive" th:if="$tweets!=null">
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Number of tweets</th>
<th>Number of followers</th>
<th>Number of users following</th>
</tr>
</thead>
<tbody>
<tr>
<td th:text="$user.id"></td>
<td th:text="$user.getUsername()"></td>
<td th:text="$tweets">1</td>
<td th:text="$followers">Hamdo</td>
<td th:text="$following "><br/>
</td>
</span>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body></html>
The controller looks like this:
@PostMapping("/")
@ResponseStatus(CREATED)
public String tweet(@ModelAttribute("tweet") @Valid @RequestBody String
tweet, Principal principal, BindingResult result)
if(result.hasErrors())
return "error";
tweetService.createTweet(tweet, principal);
return "index";
Thanks you with the help in advance and i m newbie with Thymleaf.
java html spring spring-boot thymeleaf
add a comment |
I m getting an error when i want to introduce another fragment from one layout page that contains to fragments. The one is for the header and the other for a post form. When i include just the first one I m getting a problem but if I add the other one i m getting two errors.
The first one is:
Error during execution of processor 'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor' (template: "fragments/header" - line 38, col 26)
The second one is
` ERROR 13400 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]
: Servlet.service() for servlet [dispatcherServlet] in context with path
[/api] threw exception [Request processing failed; nested exception is
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution
of processor
'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor'
(template: "fragments/header" - line 38, col 26)] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target
object for bean name 'tweet' available as request attribute`
The first fragment is a navigation bar and the second is post form. I was using thymleaf and spring boot.
The header.html is:
<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
...
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#"><strong>Twitter</strong></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li th:classappend="$module == 'home' ? 'active' : ''">
<a href="#" th:href="@/">My tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/new">Create a User</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/tweets">Tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/all">Display all Users</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/overview">Profile overview</a>
</li>
</ul>
</div>
</div>
</div>
<div th:fragment="post">
<!--/*@thymesVar id="tweet"
type="com.javalanguagezone.interviewtwitter.domain.Tweet"*/-->
<form th:action="@/tweets/" th:object="$tweet" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening?
Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>
The html file where i m calling the layout fragments looks like this:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8">
<title>User overview</title>
</head>
<body>
<div th:replace="fragments/header :: header"></div>
<div th:replace="fragments/header :: post"></div>
<div class="container-fluid" style="margin-top: 80px">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">User profile overview</h1>
</div>
<div class="panel-body">
<div class="table-responsive" th:if="$tweets!=null">
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Number of tweets</th>
<th>Number of followers</th>
<th>Number of users following</th>
</tr>
</thead>
<tbody>
<tr>
<td th:text="$user.id"></td>
<td th:text="$user.getUsername()"></td>
<td th:text="$tweets">1</td>
<td th:text="$followers">Hamdo</td>
<td th:text="$following "><br/>
</td>
</span>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body></html>
The controller looks like this:
@PostMapping("/")
@ResponseStatus(CREATED)
public String tweet(@ModelAttribute("tweet") @Valid @RequestBody String
tweet, Principal principal, BindingResult result)
if(result.hasErrors())
return "error";
tweetService.createTweet(tweet, principal);
return "index";
Thanks you with the help in advance and i m newbie with Thymleaf.
java html spring spring-boot thymeleaf
add a comment |
I m getting an error when i want to introduce another fragment from one layout page that contains to fragments. The one is for the header and the other for a post form. When i include just the first one I m getting a problem but if I add the other one i m getting two errors.
The first one is:
Error during execution of processor 'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor' (template: "fragments/header" - line 38, col 26)
The second one is
` ERROR 13400 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]
: Servlet.service() for servlet [dispatcherServlet] in context with path
[/api] threw exception [Request processing failed; nested exception is
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution
of processor
'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor'
(template: "fragments/header" - line 38, col 26)] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target
object for bean name 'tweet' available as request attribute`
The first fragment is a navigation bar and the second is post form. I was using thymleaf and spring boot.
The header.html is:
<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
...
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#"><strong>Twitter</strong></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li th:classappend="$module == 'home' ? 'active' : ''">
<a href="#" th:href="@/">My tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/new">Create a User</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/tweets">Tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/all">Display all Users</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/overview">Profile overview</a>
</li>
</ul>
</div>
</div>
</div>
<div th:fragment="post">
<!--/*@thymesVar id="tweet"
type="com.javalanguagezone.interviewtwitter.domain.Tweet"*/-->
<form th:action="@/tweets/" th:object="$tweet" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening?
Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>
The html file where i m calling the layout fragments looks like this:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8">
<title>User overview</title>
</head>
<body>
<div th:replace="fragments/header :: header"></div>
<div th:replace="fragments/header :: post"></div>
<div class="container-fluid" style="margin-top: 80px">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">User profile overview</h1>
</div>
<div class="panel-body">
<div class="table-responsive" th:if="$tweets!=null">
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Number of tweets</th>
<th>Number of followers</th>
<th>Number of users following</th>
</tr>
</thead>
<tbody>
<tr>
<td th:text="$user.id"></td>
<td th:text="$user.getUsername()"></td>
<td th:text="$tweets">1</td>
<td th:text="$followers">Hamdo</td>
<td th:text="$following "><br/>
</td>
</span>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body></html>
The controller looks like this:
@PostMapping("/")
@ResponseStatus(CREATED)
public String tweet(@ModelAttribute("tweet") @Valid @RequestBody String
tweet, Principal principal, BindingResult result)
if(result.hasErrors())
return "error";
tweetService.createTweet(tweet, principal);
return "index";
Thanks you with the help in advance and i m newbie with Thymleaf.
java html spring spring-boot thymeleaf
I m getting an error when i want to introduce another fragment from one layout page that contains to fragments. The one is for the header and the other for a post form. When i include just the first one I m getting a problem but if I add the other one i m getting two errors.
The first one is:
Error during execution of processor 'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor' (template: "fragments/header" - line 38, col 26)
The second one is
` ERROR 13400 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]
: Servlet.service() for servlet [dispatcherServlet] in context with path
[/api] threw exception [Request processing failed; nested exception is
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution
of processor
'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor'
(template: "fragments/header" - line 38, col 26)] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target
object for bean name 'tweet' available as request attribute`
The first fragment is a navigation bar and the second is post form. I was using thymleaf and spring boot.
The header.html is:
<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
...
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#"><strong>Twitter</strong></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li th:classappend="$module == 'home' ? 'active' : ''">
<a href="#" th:href="@/">My tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/new">Create a User</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/tweets">Tweets</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/all">Display all Users</a>
</li>
<li th:classappend="$module == 'tasks' ? 'active' : ''">
<a href="#" th:href="@/overview">Profile overview</a>
</li>
</ul>
</div>
</div>
</div>
<div th:fragment="post">
<!--/*@thymesVar id="tweet"
type="com.javalanguagezone.interviewtwitter.domain.Tweet"*/-->
<form th:action="@/tweets/" th:object="$tweet" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening?
Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>
The html file where i m calling the layout fragments looks like this:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8">
<title>User overview</title>
</head>
<body>
<div th:replace="fragments/header :: header"></div>
<div th:replace="fragments/header :: post"></div>
<div class="container-fluid" style="margin-top: 80px">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">User profile overview</h1>
</div>
<div class="panel-body">
<div class="table-responsive" th:if="$tweets!=null">
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Number of tweets</th>
<th>Number of followers</th>
<th>Number of users following</th>
</tr>
</thead>
<tbody>
<tr>
<td th:text="$user.id"></td>
<td th:text="$user.getUsername()"></td>
<td th:text="$tweets">1</td>
<td th:text="$followers">Hamdo</td>
<td th:text="$following "><br/>
</td>
</span>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body></html>
The controller looks like this:
@PostMapping("/")
@ResponseStatus(CREATED)
public String tweet(@ModelAttribute("tweet") @Valid @RequestBody String
tweet, Principal principal, BindingResult result)
if(result.hasErrors())
return "error";
tweetService.createTweet(tweet, principal);
return "index";
Thanks you with the help in advance and i m newbie with Thymleaf.
java html spring spring-boot thymeleaf
java html spring spring-boot thymeleaf
edited Nov 16 '18 at 6:50
Alain Cruz
2,1003920
2,1003920
asked Nov 15 '18 at 13:10
Jasmin Jasko MerušićJasmin Jasko Merušić
657
657
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can try passing down the tweet
object as variable to your fragment with the following code.
<div th:replace="fragments/header :: post" th:with="tweetFrag = $tweet"></div>
Then, just use the new variable.
<form th:action="@/tweets/" th:object="$tweetFrag" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening? Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320255%2fhow-can-i-solve-the-problem-with-my-multiple-layouts-in-thymleaf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try passing down the tweet
object as variable to your fragment with the following code.
<div th:replace="fragments/header :: post" th:with="tweetFrag = $tweet"></div>
Then, just use the new variable.
<form th:action="@/tweets/" th:object="$tweetFrag" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening? Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
add a comment |
You can try passing down the tweet
object as variable to your fragment with the following code.
<div th:replace="fragments/header :: post" th:with="tweetFrag = $tweet"></div>
Then, just use the new variable.
<form th:action="@/tweets/" th:object="$tweetFrag" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening? Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
add a comment |
You can try passing down the tweet
object as variable to your fragment with the following code.
<div th:replace="fragments/header :: post" th:with="tweetFrag = $tweet"></div>
Then, just use the new variable.
<form th:action="@/tweets/" th:object="$tweetFrag" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening? Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
You can try passing down the tweet
object as variable to your fragment with the following code.
<div th:replace="fragments/header :: post" th:with="tweetFrag = $tweet"></div>
Then, just use the new variable.
<form th:action="@/tweets/" th:object="$tweetFrag" method="post">
<div class="form-group">
<input type="text" th:field="*content" placeholder="What's happening? Tell us!">+
<input type="submit" value="Submit" />
</div>
</form>
answered Nov 15 '18 at 20:26
Alain CruzAlain Cruz
2,1003920
2,1003920
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320255%2fhow-can-i-solve-the-problem-with-my-multiple-layouts-in-thymleaf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown