This are the steps that I followed : -
- Created a controller named MyController with this code
Code: Select all
@Controller
@RequestMapping("/" + MyController.SECTION_KEY)
@Secured("PERMISSION_OTHER_DEFAULT")
public class MyController extends AdminAbstractController {
protected static final String SECTION_KEY = "test";
@RequestMapping(value = "", method = RequestMethod.GET)
public String test(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
// This is expected by the modules/emptyContainer template, this is a custom template that gets included into the body
model.addAttribute("customView", "test");
// Test custom thymeleaf form display and field binding to back end custom pojo class
model.addAttribute("greeting", new Greeting());
// ensure navigation gets set up correctly
setModelAttributes(model, SECTION_KEY);
// gets the scaffolding set up to display the template from the customView attribute above
return "modules/emptyContainer";
}
@RequestMapping(value="/greeting", method = RequestMethod.POST)
public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
model.addAttribute("customView", "result");
// Test custom thymeleaf form display and field binding to back end custom pojo class
model.addAttribute("greeting", greeting);
// Ensure navigation gets set up correctly
setModelAttributes(model, SECTION_KEY);
// gets the scaffolding set up to display the template from the customView attribute above
return "modules/emptyContainer";
}
}
Made this addition to the applicationContext-servlet-admin.xml file
Code: Select all
<context:component-scan base-package="com.myco.admin.web" />
So that spring finds my controller class
Next I created 2 fragment html files name test.html with content
Code: Select all
<div class="row">
<div class="twelve columns">
<h1>Form</h1>
<blc:form action="#" th:action="@{/greeting}" th:object="${greeting}" method="post">
<p>Id: <input type="text" th:field="*{id}" /></p>
<p>Message: <input type="text" th:field="*{content}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</blc:form>
</div>
</div>
and result.html with content
Code: Select all
<div class="row">
<div class="twelve columns">
<h1>Result</h1>
<p th:text="'id: ' + ${greeting.id}" />
<p th:text="'content: ' + ${greeting.content}" />
<a href="/greeting">Submit another message</a>
</div>
</div>
in the following locations
Code: Select all
WEB-INF/templates/layout/partials/test.html
WEB-INF/templates/layout/partials/result.html
of the admin module
I have this entry for the view resolver
Code: Select all
<bean id="blAdminWebTemplateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/layout/partials/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="${cache.page.templates}"/>
<property name="cacheTTLMs" value="${cache.page.templates.ttl}" />
<property name="characterEncoding" value="UTF-8" />
<property name="order" value="200"/>
</bean>
Now when I do a post request to the server I get this error
Code: Select all
PageNotFound - Request method 'POST' not supported
Preciously when I was not using the blc tag in the view pages I was getting a CSRF Filter exception which was solved by using the blc thymeleaf processor tag but now I get this error . All the changes have been made to the admin module .
I have checked so many times but could not find a solution . Please help