Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP: Format date within a <form:input> field?

Tags:

date

jsp

I have a JSP form element that looks like:

<form:input path="foo" id="bar" value="${myObject.myDate}" class="fizz buzz bang"/>

and I want to format this date so that it initially appears like: yyyy/mm/dd

I know I can format a date in JSP easily like this:

<fmt:formatDate value="${blah.bla}" pattern="MM-dd-yyyy" />

but how can I combine the two?

When I do:

 <form:input path="foo" id="bar" value=" <fmt:formatDate value="${myObject.myDate}" pattern="MM-dd-yyyy" /> " class="fizz buzz bang"/> 

I get exceptions on the line like:

org.apache.jasper.JasperException: Unterminated form:input tag

What am I doing wrong?

like image 644
Paul Avatar asked Jul 01 '26 06:07

Paul


1 Answers

You cannot directly use <fmt:formatDate> inside the form input tag. You can format it and assign the variable to value of form input.

<fmt:formatDate value="${blah.bla}" pattern="dd/MM/yyyy" var="myDate" />
<form:input path="foo" id="bar" value="${myDate} />

Hope this helps.

  • Source

    1. Spring mvc date format with form:input

    2. How to make fmt:formatDate work for form:input

like image 122
Vinoth Krishnan Avatar answered Jul 03 '26 22:07

Vinoth Krishnan