Kevin Menard wrote:
Does anyone have any hints on getting BeanEditForm to play nicely with
collections?
For now, BeanEditor (or BeanEditForm) is not really aware of collection
as a property. I think it's in the todo list (T5 still alpha, etc ;)
So, for now I think that the only solution is to code the matching
property editor model or bean model (dependanding of what you want)
In my case, when I have a bean with both simple properties and
collection properties, I decompose its form with several beaneditor :
- one for all the simple properties ;
- one for each property witch is a collection.
For the second case, I generate a beanmodel for a fake bean in witch
each entity of the collection is a property of the fake bean (in my
case, I deal only with List, it would be easy to do the same for Map,
harder to deal with unordered collection).
So, I have a "ListStringEditor" that permits to edit, add and remove the
strings in a list. The properties editor for these string are the
standard one.
Exemple : I have a bean named "Eschema attributes" that is composed
with several simple properties and a list of possible values. According
to the explained decomposition, the EschemaAttributeEditor template
looks like :
8<--------------------------
<t:container class="attribute_details"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" >
<t:beaneditor object="attributeDefinition" model="model"/>
<t:wui-commons.eschema.listeditor
object="attributeDefinition.possibleValues"
elementClass="literal:org.interldap.ldap.objects.IByteString"/>
</t:container>
8<--------------------------
The generated html looks like :
8<--------------------------
[[propertyX]]
[[propertyY]]
[[propertyZ]]
[[possibleValue1]] [delete]
[[possibleValue2]] [delete]
[add]
8<--------------------------
(delete and add are buttons, [[..]] are text fields or whatever the
propertyeditor say it is).
You can look at the Java code her :
http://svn.forge.objectweb.org/cgi-bin/viewcvs.cgi/interldap/interldap-wui-common/trunk
wui-common/src/main/java/org/interldap/wui/t5lib/components/eschema
Hum. It seems that the browseCVS is again broken, so you should have to
checkout the code :
# svn checkout
svn://svn.forge.objectweb.org/svnroot/interldap/interldap-wui-common/trunk
wui-common
and look at :
The code that generates a BeanModel given a list :
-
wui-common/src/main/java/org/interldap/wui/t5lib/data/ListObjectBeanModelSource.java
-
wui-common/src/main/java/org/interldap/wui/t5lib/data/ListObjectPropertyConduit.java
The use case example :
* the BeanEditor for the list, with the add/delete buttons and logic :
-
wui-common/src/main/java/org/interldap/wui/t5lib/components/eschema/ListEditor.java
-
wui-common/src/main/resources/org/interldap/wui/t5lib/components/eschema/ListEditor.tml
* the eschema attribute editor that uses the ListEditor :
-
wui-common/src/main/java/org/interldap/wui/t5lib/components/eschema/ListEditor.java
-
wui-common/src/main/resources/org/interldap/wui/t5lib/components/eschema/EditAttribute.tml
And yes, I agree that it is over complicated for a simple need, but I
couldn't wait for a tapestry 5 native implementation.
Note : I gladly wait for any simplifications :)
Hope it may help,
--
Francois Armand
Etudes & Développements J2EE
Groupe Linagora - http://www.linagora.com
Tél.: +33 (0)1 58 18 68 28
-----------
InterLDAP - http://interldap.org
FederID - http://www.federid.org/
Open Source identities management and federation
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]