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?











share|improve this question
























  • 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















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?











share|improve this question
























  • 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













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?











share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











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',
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
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings