cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: Clarification on converter concept
Date Sat, 07 Jul 2007 00:36:32 GMT
On 05.07.2007 18:26, Grzegorz Kossakowski wrote:

> I had a feeling that there is much more besides Date/Number/Currency 
> formatting but now I think that I was suffering from over-generalization 
> problem. The converter concept is that simple how you describe it but 
> it's not wrong because it solves very concrete problem.

Hopefully it goes beyond simple date, number or currency formatting! 
With Spring's usage of PropertyEditors you can bind objects directly to 
a selection list. You don't care how it gets converted to string and 
back, the PropertyEditor does it. The CForms way is more complicated 
[1], you have to convert your collection to a 
org.apache.cocoon.forms.datatype.SelectionList.

In my Spring MVC project I have written one (!) EntityPropertyEditor 
which is used for all domain entities in my application. Now in JSP 
using Spring's form taglib I just write:

Which company do you want to work for?
<form:select path="user.selectedCompany" items="${companies}" 
itemLabel="name"/>

"user" is the object the form is bound to.
"selectedCompany" is a property of the use and of type entity or 
company, not a entity id or something like that.

"companies" is a collection of entities/companies, e.g. retrieved from 
RequestContext.
"name" is a property of the entity/company, here used as label.

That's all. No selection list generation. No caring about the key. The 
<option> in the <select> is correctly preselected if there was one set 
on the user. I get a company instance set on user.selectedCompany property.

>> <jx:formatDate value="${myobj.startDate}" dateStyle="short" 
>> locale="${cocoon.request.locale}">
>>
>> for each date. That is of course quite OK to write, but it clearly 
>> clutters the code, and it is not that obvious for a non developer. 
>> With converters it would be more like:
>>
>> ${myobj.startDate#short}

Isn't that only a shorter syntax?

The focus on template formatting is rather limiting. IMO it MUST be a 
two-way process or you can't write back to the object model. Selecting 
the converter in the template makes it just impossible.

We might have a different focus in mind. But if we talk about a general 
converter concept we should not start with such a limitation.

Joerg

[1] http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html

Mime
View raw message