Re: FormMaps and indexed elements/collections

Jacob Kjome <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Note that the RepopulationFormMap that Diez is talking about is in his 
contrib package.  Look under src/org/enhydra/barracuda/contrib/dbroggisch

Also, check out the example app in his contrib project under the "webapp" 
directory in that same package which actually uses the 
RepopulationFormMap.  "webapp" isn't really a package.  Everything under it 
is a complete build system for an example app complete with its own build 
file, source directory, etc...  For more information about the contrib 
projects and running the examples, see....
http://www.barracudamvc.org/Barracuda/docs/contrib_package.html


Jake

At 06:30 PM 6/5/2003 +0200, you wrote:
>Bradley Hill wrote:
>>   I haven't seen any examples or mention of it in the mail archives, but 
>> this has to be a common issue.
>>
>>   I'm looking to create forms with indexed property sets, e.g. name1, 
>> name2, nameN, value1, value2, valueN.  I don't know until runtime how 
>> many of these properties there will be.
>>
>>   Is there a way to handle arrays and collections of values in the 
>> Barracuda forms validation package?  Struts will recognize and map 
>> parameters with names like "name[n]" and insert them properly into beans 
>> with indexed getter/setter methods.  Is there similar functionality in 
>> Barracuda or would it be easy for me to add?
>
>If you want to map and validate such values, things are easy: As HTML 
>doesn't know anything about indexed/mapped values, you will have to create 
>distinct names for every entry in your collection. E.g. for a list you do
>
><input type="text" name="mylist_1" value="foo"/>
>
>Its no problem to create a FormMap with a element for every single of 
>these input fields.
>
>The only thing missing is a convinience-function to access such a list of 
>values. But thats not too hard - simply extend DefaultFormMap (or 
>RepopulationFormMap) with methods like these (beware of pseudo-code):
>
>public Map getElementAsMap(String prefix) {
>         Map result = new HashMap();
>         for(FormElement element in getElements()) {
>            if(element.getName().startsWith(prefix)) {
>               result.put(element.getName().substring(prefix.length() + 
> 1), element.getVal());
>            }
>         }
>         return result;
>}
>
>For a list, you want to convert the keys to ints and put the values into 
>the result at the specified position.
>
>
>Now, for rendering such stuff, things get a little bit more complicated. 
>For every mapped/indexed value, you have to create a IterativeModel, so 
>you can populate its data.
>
>I could imagine the 2 new FormElements for the RepopulationFormMap could 
>add your functionality quite easy - look into CheckBoxGroupElement. Then 
>you could even access the value directly as Map/List with getElement(name) 
>on RepopulationFormMap.
>
>
>Regards, Diez
>
>_______________________________________________
>Barracuda mailing list
>[email protected]
>http://barracudamvc.org/lists/listinfo/barracuda
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.