How to make fmt:formatDate work for form:input

无人久伴 提交于 2019-12-03 23:29:01

You can't use a JSP tag in an attribute of another JSP tag. STore the result of the date formatting in a page attribute, and use this page attribute (as you would do with a variable in Java):

<fmt:formatDate value="transactions['${loopStatus.index}'].valueTransactionDate"  
                type="date" 
                pattern="yyyy-MM-dd"
                var="theFormattedDate" />
<form:input type="text" path="..." value="${theFormattedDate}"/>

In the latest releases of the spring JSTL tags you can't use the attribute value into de tah form:input. If you try, you will get a value attribute is not valid for tag <form:input> error.

In this case you must use a normal HTML input tag and put the path as the name of the input to trigger the binding to the Spring form like this

<fmt:formatDate var="fmtDate" value="${form.bean.dateProperty}" pattern="dd/MM/yyyy"/>
<input type="text" name="bean.dateProperty" value="${fmtDate}"/>

Ugly but works for me! ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!