cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Gianni <s.gia...@thebug.it>
Subject Forms enum selection list order
Date Wed, 01 Mar 2006 23:35:29 GMT
Hi team,
cocoon forms uses the common enumeration pattern for it's enum datatype 
and selection list. The problem with the selection list is that the 
order of the elements in it is not granted. Current implementation uses 
the getDeclaredFields method, which states in its javadocs that " The 
elements in the array returned are not sorted and are not in any 
particular order".

Unfortunately, it's quite common for the customer to need elements in a 
specific order. For example, in a payment options combo, they want to 
see the various credit cards first, then other online payment methods, 
then bank transactions etc.. And this is very critical for them, and 
honestly quite horrible to see them mixed.

Actually, with sun JRE for windows and linux they appear in the right 
order, but it's just a matter of implementation, since on other JREs 
and/or platforms (and most notably, on IBM JREs, used by WebSphere) they 
are in a random order.

There is no way to make them appear in the "right" order, but in a 
project we had this issue and solved them using the apache commons 
enums. In this enums, the enum fields are added to a list while they are 
declared, and using this list instead of the getDeclaredFields gives 
them in the declaration order also on other JRE implementations.

This also gives more control : by overriding the getList method of the 
enum class, the developer can change the order directly from the enum 
class, without involving front-end work and still maintaining a 
selection list of type enum instead of a static unrolled selection list.

I developed an ApacheEnumSelectionList class and I'm ready to contribute 
it, but i think it would be nicer to "merge" this code in the actual 
EnumSelectionList, so that if the given enum is an apache enum, the 
getList method is used instead of the getDeclaredFields method.

I can provide a patch shortly, WDYT?

Simone

-- 
Simone Gianni

Mime
View raw message