0

I am changing some code from a home grown MVC to Spring 2.5 MVC. We have a form to edit an object, so I am using formBackingObject() in my controller to populate the form fields with the current values. In the old MVC, we used the JSTL fmt taglib to format date and money fields. This was nice because the formatting was in the presentation layer.

Now with Spring, the fields are populated correctly with formBackingObject(), but Spring doesn't recognize the the value attribute in the form:input element:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<form:form method="post" commandName="editProgramCommand" name="editTitleForm">
  <fmt:formatNumber type="NUMBER" value="${program.price}" var="formattedPrice" minFractionDigits="2" />
  <form:input path="price" id="price" value="${formattedPrice}" />
  ... other fields
</form:form>

Thoughts on how to properly format values in a Spring form? I'm not finding much on the web, so I figure its either a really simple syntax error, or I'm completely on the wrong track.

4

1 に答える 1

0

Springは、属性からではなく、form:inputその属性から入力の値を認識します。スプリング フォーム tldが表示される場合、フォーム入力タグの属性値はありません。pathvalue

  1. 私が考える1つの方法は、バックエンドで値をフォーマットし、それをフロントエンドに持ってきて設定することです。
  2. spring:bindそれ以外の場合は、スプリング フォームの代わりに従来のフォームを使用できます。スプリング バインド リファレンス
于 2012-05-09T19:14:49.973 に答える