|
From: Olivier J. <oli...@pc...> - 2004-09-02 20:46:14
|
Greetings all,
while trying to bring spring into the developments of my company, I
faced the following issue which I think could lead to an improvement :
We have a command in a simpleForm with some custom type component at
top. Some of those objects contains a Map storing Date.
The point is that I'd like to use a custom DateEditor to format them
when rendering my view and when bind them to the command.
I made a custom DateEditor and I registered it. It works fine for
gettings String from the request and filling my command but when
rendering the view, as I use the spring taglib to bind on the map
containing the object with Date inside, the eventual custom
PropertyEditor is given called with the whole map and the result is
compulsory a String
(org.springframework.validation.BindException.getFieldValue).
What could be slightly more powerful is to allow to return Object, by
calling getValue instead of getAsText. In order to achieve ascendant
compatibility and have getAsText called by default, we could provide an
Interface (either empty or with the getValue method, both ways are
unperfect, I know) like ObjectReturningPropertyEditorInterface which
would enable the getFieldValue method to check whether the getAsText or
getValue method should be invoked.
This way I could code a PropertyEditor, implementing the new interface,
overriding the getValue by returning a copy of the map given in setValue
and altering the value by remplacing incoming Date bucklets with a
formatted result.
If this sounds ok, I would be honored to propose a patch against CVS
head even if it's not for including into 1.1 final.
I'm not sure I've been clear enough, my jsp code looks like this :
<spring:bind path="command.customer">
<%-- customer is an instance of a Customer which contains a collection
of Affectation --%>
<c:foreach items="${affectations}" var="affectation">
<%-- the Affectation class mainly contains a couple of Date that I
what to format --%>
<tr><td><INPUT type="text"
name="fake_map_for_catching_setting_of_begin_date[<c:out
value="${affectation.id}"/>]" <c:out value="${affectation.beginDate}"/> ....
</c:foreach>
</spring:bind>
I'd really be happy to provide my first patch to spring if my idea could
bring something interesting to the whole.
Greetings
Olivier Jolly
|