Convert Thymeleaf “th:field” in Freemarker
up vote
0
down vote
favorite
I convert my project from Thymeleaf to Freemaker. I have one problem. Now I’ll try to describe it.
On the main page of my site there are list of vendors and a search field that searches for vendors by name.
In Thymeleaf it looks something like this-
Controller:
@GetMapping("/vendors")
public String getAllVendors(Model model,@PageableDefault Pageable pageable){
Page<Vendors> vendors = vendorRepository.findAll(pageable);
model.addAttribute("searchVendor",new Foo()); //This is for search field
model.addAttribute("url","/vendors");
model.addAttribute("vendors",vendors);
return "vendors/list";
}
Foo class:
@Getter
@Setter
public class Foo {
private List<Long> checkedItems; // for checkboxes
private List<Long> checkedItemsPlus; //for checkboxes
private String findItem; // to find by the name
private Long findSupply; // to find by the id
private String findItemPlus; // to find by the second name
}
Thymeleaf template (form for search field):
<form th:action="@{/showVendor}" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2"
th:field="${searchVendor.findItem}" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success">
Search
</button>
</form>
${searchVendor.findItem}-this is the string in which the entered name
is written.
Controller
@PostMapping("/showVendor")
public String getVendorBySearch(Model model,@ModelAttribute("searchVendor") Foo foo){
model.addAttribute("vendors",
vendorService.getVendorByName(foo.getFindItem()));
return "vendors/show";
}
Thats all works fine with Thymeleaf.
In Freemaker i changed only my thymeleaf template -
Freemaker template
<form action="/showVendor" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2" value="${searchVendor.findItem}" id="findItem" name="findItem" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success my-2 my-sm-0">Search</button>
</form>
I'm not sure about that, but replaced th:field on value, id, name
Then i click button i have this error-
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Nov 07 21:42:23 MSK 2018
There was an unexpected error (type=Forbidden, status=403).
Forbidden
And my final questions.How to replace th:field from Thymeleaf to
Freemaker? Did I do it right or i need to do something else? Why does this error come?
java spring thymeleaf freemarker
add a comment |
up vote
0
down vote
favorite
I convert my project from Thymeleaf to Freemaker. I have one problem. Now I’ll try to describe it.
On the main page of my site there are list of vendors and a search field that searches for vendors by name.
In Thymeleaf it looks something like this-
Controller:
@GetMapping("/vendors")
public String getAllVendors(Model model,@PageableDefault Pageable pageable){
Page<Vendors> vendors = vendorRepository.findAll(pageable);
model.addAttribute("searchVendor",new Foo()); //This is for search field
model.addAttribute("url","/vendors");
model.addAttribute("vendors",vendors);
return "vendors/list";
}
Foo class:
@Getter
@Setter
public class Foo {
private List<Long> checkedItems; // for checkboxes
private List<Long> checkedItemsPlus; //for checkboxes
private String findItem; // to find by the name
private Long findSupply; // to find by the id
private String findItemPlus; // to find by the second name
}
Thymeleaf template (form for search field):
<form th:action="@{/showVendor}" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2"
th:field="${searchVendor.findItem}" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success">
Search
</button>
</form>
${searchVendor.findItem}-this is the string in which the entered name
is written.
Controller
@PostMapping("/showVendor")
public String getVendorBySearch(Model model,@ModelAttribute("searchVendor") Foo foo){
model.addAttribute("vendors",
vendorService.getVendorByName(foo.getFindItem()));
return "vendors/show";
}
Thats all works fine with Thymeleaf.
In Freemaker i changed only my thymeleaf template -
Freemaker template
<form action="/showVendor" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2" value="${searchVendor.findItem}" id="findItem" name="findItem" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success my-2 my-sm-0">Search</button>
</form>
I'm not sure about that, but replaced th:field on value, id, name
Then i click button i have this error-
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Nov 07 21:42:23 MSK 2018
There was an unexpected error (type=Forbidden, status=403).
Forbidden
And my final questions.How to replace th:field from Thymeleaf to
Freemaker? Did I do it right or i need to do something else? Why does this error come?
java spring thymeleaf freemarker
Freemarker is a simpler system than Thymeleaf, and I don't think it has the concept of model binding.
– chrylis
Nov 7 at 19:11
So how can I pass the entered value from my search field to the controller? Do you know?
– Maxim Sukhodolets
Nov 7 at 19:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I convert my project from Thymeleaf to Freemaker. I have one problem. Now I’ll try to describe it.
On the main page of my site there are list of vendors and a search field that searches for vendors by name.
In Thymeleaf it looks something like this-
Controller:
@GetMapping("/vendors")
public String getAllVendors(Model model,@PageableDefault Pageable pageable){
Page<Vendors> vendors = vendorRepository.findAll(pageable);
model.addAttribute("searchVendor",new Foo()); //This is for search field
model.addAttribute("url","/vendors");
model.addAttribute("vendors",vendors);
return "vendors/list";
}
Foo class:
@Getter
@Setter
public class Foo {
private List<Long> checkedItems; // for checkboxes
private List<Long> checkedItemsPlus; //for checkboxes
private String findItem; // to find by the name
private Long findSupply; // to find by the id
private String findItemPlus; // to find by the second name
}
Thymeleaf template (form for search field):
<form th:action="@{/showVendor}" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2"
th:field="${searchVendor.findItem}" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success">
Search
</button>
</form>
${searchVendor.findItem}-this is the string in which the entered name
is written.
Controller
@PostMapping("/showVendor")
public String getVendorBySearch(Model model,@ModelAttribute("searchVendor") Foo foo){
model.addAttribute("vendors",
vendorService.getVendorByName(foo.getFindItem()));
return "vendors/show";
}
Thats all works fine with Thymeleaf.
In Freemaker i changed only my thymeleaf template -
Freemaker template
<form action="/showVendor" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2" value="${searchVendor.findItem}" id="findItem" name="findItem" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success my-2 my-sm-0">Search</button>
</form>
I'm not sure about that, but replaced th:field on value, id, name
Then i click button i have this error-
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Nov 07 21:42:23 MSK 2018
There was an unexpected error (type=Forbidden, status=403).
Forbidden
And my final questions.How to replace th:field from Thymeleaf to
Freemaker? Did I do it right or i need to do something else? Why does this error come?
java spring thymeleaf freemarker
I convert my project from Thymeleaf to Freemaker. I have one problem. Now I’ll try to describe it.
On the main page of my site there are list of vendors and a search field that searches for vendors by name.
In Thymeleaf it looks something like this-
Controller:
@GetMapping("/vendors")
public String getAllVendors(Model model,@PageableDefault Pageable pageable){
Page<Vendors> vendors = vendorRepository.findAll(pageable);
model.addAttribute("searchVendor",new Foo()); //This is for search field
model.addAttribute("url","/vendors");
model.addAttribute("vendors",vendors);
return "vendors/list";
}
Foo class:
@Getter
@Setter
public class Foo {
private List<Long> checkedItems; // for checkboxes
private List<Long> checkedItemsPlus; //for checkboxes
private String findItem; // to find by the name
private Long findSupply; // to find by the id
private String findItemPlus; // to find by the second name
}
Thymeleaf template (form for search field):
<form th:action="@{/showVendor}" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2"
th:field="${searchVendor.findItem}" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success">
Search
</button>
</form>
${searchVendor.findItem}-this is the string in which the entered name
is written.
Controller
@PostMapping("/showVendor")
public String getVendorBySearch(Model model,@ModelAttribute("searchVendor") Foo foo){
model.addAttribute("vendors",
vendorService.getVendorByName(foo.getFindItem()));
return "vendors/show";
}
Thats all works fine with Thymeleaf.
In Freemaker i changed only my thymeleaf template -
Freemaker template
<form action="/showVendor" method="post" class="form-inline">
<input type="search" class="form-control mr-sm-2" value="${searchVendor.findItem}" id="findItem" name="findItem" placeholder="Search By Name"/>
<button type="submit" class="btn btn-outline-success my-2 my-sm-0">Search</button>
</form>
I'm not sure about that, but replaced th:field on value, id, name
Then i click button i have this error-
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Nov 07 21:42:23 MSK 2018
There was an unexpected error (type=Forbidden, status=403).
Forbidden
And my final questions.How to replace th:field from Thymeleaf to
Freemaker? Did I do it right or i need to do something else? Why does this error come?
java spring thymeleaf freemarker
java spring thymeleaf freemarker
edited Nov 7 at 18:57
asked Nov 7 at 18:49
Maxim Sukhodolets
284
284
Freemarker is a simpler system than Thymeleaf, and I don't think it has the concept of model binding.
– chrylis
Nov 7 at 19:11
So how can I pass the entered value from my search field to the controller? Do you know?
– Maxim Sukhodolets
Nov 7 at 19:21
add a comment |
Freemarker is a simpler system than Thymeleaf, and I don't think it has the concept of model binding.
– chrylis
Nov 7 at 19:11
So how can I pass the entered value from my search field to the controller? Do you know?
– Maxim Sukhodolets
Nov 7 at 19:21
Freemarker is a simpler system than Thymeleaf, and I don't think it has the concept of model binding.
– chrylis
Nov 7 at 19:11
Freemarker is a simpler system than Thymeleaf, and I don't think it has the concept of model binding.
– chrylis
Nov 7 at 19:11
So how can I pass the entered value from my search field to the controller? Do you know?
– Maxim Sukhodolets
Nov 7 at 19:21
So how can I pass the entered value from my search field to the controller? Do you know?
– Maxim Sukhodolets
Nov 7 at 19:21
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53195904%2fconvert-thymeleaf-thfield-in-freemarker%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
Freemarker is a simpler system than Thymeleaf, and I don't think it has the concept of model binding.
– chrylis
Nov 7 at 19:11
So how can I pass the entered value from my search field to the controller? Do you know?
– Maxim Sukhodolets
Nov 7 at 19:21