There is one thing that bugs me a lot when dealing with cforms and that is: the need for unique repeater id.

Does anyone have a nice solution for something like this:
A form is bound to and O/R managed bean:

class Net {
        private String name;

        // elements of class Depot
        Set depots;
}

depots could be shown using a repeater like this:
<fd:repeater id="depots">
    <fd:label>Hale</fd:label>
    <fd:widgets>
        <fd:output id="id">
            <fd:label>id</fd:label>
            <fd:datatype base="long"/>
        </fd:output>
        <fd:field id="name">
            <fd:label>Name</fd:label>
            <fd:datatype base="string"/>
        </fd:field>
        <fd:submit id="edit-depot" action-command="-">
            <fd:label>edit</fd:label>
        </fd:submit>
    </fd:widgets>
</fd:repeater>

Now you want to add a depot somehow. That's easy - simple fd:submit with validate = false. Problem is you have to assign a unique id but you need the id to be null so the bean will be persisted as new. You cannot use repeater action as this would insert an empty Depot bean into the collection and mess everything up.

So you have to:
1. assign a temporal id somehow unique from all existing
2. then remove it (nullify) after form.save and before the bean is persisted

it got really bad:
1. the id has to be somehow different from the "persistent" one ( <0 ? )
2. if you edit a deeper structure nullifying the temporal ids gets really ugly.

Finally: you cannot use simple repeater which will delete and overwrite whole collection as this would break database constraints.

Please comment.
--
Leszek Gawron                                      [EMAIL PROTECTED]



Reply via email to