Reputation: 12940
I would like to use spring Boot MVC with Freemarker and display a form in a similar way to how it is done with JSP tags. E.g. this form:
<form:form method="post" action="save" modelAttribute="form" class="form-horizontal">
<form:hidden path="id"/>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<form:input id="name" path="name" class="form-control" />
</div>
</div>
</form:form>
Naturally, the tags form:form, form:input, form:hidden etc. are not supported. Is there a way to bind the model to the view in Freemarker?
Upvotes: 0
Views: 7817
Reputation: 12940
Here it is:
<!-- freemarker macros have to be imported into a namespace. We strongly
recommend sticking to spring -->
<#import "/spring.ftl" as spring />
<html>
...
<form action="" method="POST">
Name:
<@spring.bind "command.name" />
<input type="text"
name="${spring.status.expression}"
value="${spring.status.value?default("")}" /><br>
<#list spring.status.errorMessages as error> <b>${error}</b> <br> </#list>
<br>
...
<input type="submit" value="submit"/>
</form>
...
</html>
Upvotes: 4