Skip to content

Conversation

@xhaggi
Copy link

@xhaggi xhaggi commented Apr 7, 2017

This PR will introduce a new freemarker template spring-form.ftl for proper form handling similar to the spring tag library and in addition it improves some of the existing message macros.

spring-form.ftl
Here is a quick example of how the new form macros work.

<#import "spring-form.ftl" as form /> <#-- form --> <@form.form modelAttribute="myForm"> <#-- input field with various attributes which are supported by most of the elements --> <@form.input path="field" cssClass="myclass" cssErrorClass="myclass error" style="color:red;" data_role="role" .... /> <#-- hidden --> <@form.hidden path="field" /> <#-- password --> <@form.password path="field" /> <#-- textarea --> <@form.textarea path="field" /> <#-- checkbox --> <@form.checkbox path="field" /> <#-- checkbox --> <@form.radio path="field" /> <#-- select element, with some options --> <@form.select path="field" cssClass="myclass" cssErrorClass="myclass error"> <@form.option value="value1">Value 1</@form.option> <@form.option value="value2">Value 2</@form.option> </@form.select> <#-- output global errors --> <@form.errors ; errors> <#list errors as error> <p>${error}</p> </#list> </@form.errors> <#-- output field errors --> <@form.errors path="field" ; errors> <#list errors as error> <p>${error}</p> </#list> </@form.errors> </@form.form> <#-- output global errors outside a form --> <@form.errors path="myForm" ; errors> <#list errors as error> <p>${error}</p> </#list> </@form.errors> <#-- output field errors outside a form --> <@form.errors path="myForm.field" ; errors> <#list errors as error> <p>${error}</p> </#list> </@form.errors>

Most of the marcos are similar to the existing elements in the spring tag library. They also cover the type conversion via PropertyEditor to parse and format property values in the same way as the JSP tag library.

spring.ftl

<@spring.message code args=[] text=""> <@spring.theme code args=[] text="">

Both macros now support optional parameters so there is now need to use the other marcos messageText, messageArgsText, themeText, themeArgsText anymore. I've marked them deprecated, but let me know if we should remove them.

This PR is currently WIP, because the test cases fail and need some more love. Before I spent more time in this, let me know if this PR might be interesting and will be merged if everything is fine.

@xhaggi xhaggi force-pushed the spring-ftl-macros branch from de5d127 to 439f657 Compare April 7, 2017 09:02
@xhaggi xhaggi force-pushed the spring-ftl-macros branch 4 times, most recently from 835c110 to d177a9c Compare April 21, 2017 10:11
@xhaggi xhaggi force-pushed the spring-ftl-macros branch from d177a9c to 5e2b9e9 Compare May 9, 2017 11:27
@xhaggi
Copy link
Author

xhaggi commented Jun 21, 2017

@jhoeller mind taking a look

@xhaggi xhaggi force-pushed the spring-ftl-macros branch 2 times, most recently from 12a0332 to f19fc77 Compare October 20, 2017 07:29
@xhaggi xhaggi force-pushed the spring-ftl-macros branch from f19fc77 to 5353b4f Compare October 20, 2017 07:34
@xhaggi
Copy link
Author

xhaggi commented Mar 6, 2018

This PR is obsolete because Spring's "Web MVC framework" functionality was added to the sub-module freemarker-spring of the upcoming Freemarker 3.x.

https://issues.apache.org/jira/browse/FREEMARKER-55
https://github.com/apache/incubator-freemarker/tree/3/freemarker-spring

@xhaggi xhaggi closed this Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant