Hi Viktor,
I presume you are referring to the table example in the tutorial. There I am
using a Direct link, so there is no rewind and that problem cannot occur. I
am guessing you are doing the removal within a form, which would make the
scenario you describe possible.
I can think of a couple of quick fixes that should resolve this situation:
a) clone the list and pass an iterator of the clone to the Foreach
b) delay the actual removal of the elements until the formSubmit() listener
is called (accumulate the ones to delete in an array or sth like that)
Would those help?
Best regards,
-mb
----- Original Message -----
From: "Viktor Szathmary" <[EMAIL PROTECTED]>
To: "Tapestry Developers" <[EMAIL PROTECTED]>
Sent: Sunday, January 05, 2003 1:02 AM
Subject: [Tapestry-developer] concurrent modification problem in a dynamic
form
> hi,
>
> i have a form with a ForEach, and i would like to dynamically add/remove
> elements from the underlying list. Adding an element works fine, but when
> removing an element from the middle of the list, i get a
> ConcurrentModificationException. I understand why this would occur - i'm
> messing up the iterator that the ForEach is using.. However, i don't see
> the way out from this. The Table component does something similar, but
> it's a little complicated for me to figure it out based on it's
> implementation...
>
> any suggestions would be appreciated...
>
> viktor
>
> here's the page's source and definition (i cut out irrelevant details):
>
> public class AddTimeslots extends BasePage {
>
> private List timeslots;
> private int selectedTimeslotIndex;
>
> protected void initialize() {
> super.initialize();
> this.timeslots = new ArrayList();
> this.timeslots.add( new DlvTimeslotModel() );
> }
>
> public void addTimeslot(IRequestCycle cycle){
> if (this.validateTimeslots()) {
> this.timeslots.add( new DlvTimeslotModel() );
> }
> }
>
> public void setSelectedTimeslotIndex(int selectedTimeslotIndex) {
> this.selectedTimeslotIndex = selectedTimeslotIndex;
> }
>
> public void deleteTimeslot(IRequestCycle cycle){
> this.timeslots.remove(this.selectedTimeslotIndex);
> }
>
> private boolean validateTimeslots() {
> // ... do validation
> }
>
> public List getTimeslots() {
> return timeslots;
> }
>
> public int getTimeslotCount() {
> return this.timeslots.size();
> }
>
> public void setTimeslotCount(int timeslotCount) {
> this.timeslots.clear();
> for (int i=0; i<timeslotCount; i++) {
> this.timeslots.add( new DlvTimeslotModel() );
> }
> }
>
> }
>
>
>
> <page-specification class="com.freshdirect.dlvadmin.AddTimeslots">
>
> <bean name="delegate" class="net.sf.tapestry.valid.ValidationDelegate"
> lifecycle="request"/>
>
> <component id="border" type="Border">
> <static-binding name="title">Add Timeslot</static-binding>
> </component>
>
> <component id="forEachTimeslot" type="Foreach">
> <binding name="source" expression='timeslots'/>
> </component>
>
> <component id="formAddSlot" type="Form">
> <binding name="delegate" expression='beans.delegate'/>
> <binding name="stateful" expression='false'/>
> </component>
>
> <component id="submitAddTimeslot" type="Submit">
> <binding name="listener" expression='listeners.addTimeslot'/>
> </component>
>
> <component id="submitDeleteTimeslot" type="Submit">
> <binding name="listener" expression='listeners.deleteTimeslot'/>
> <binding name="selected" expression='selectedTimeslotIndex'/>
> <binding name="tag" expression='components.forEachTimeslot.index'/>
> </component>
>
> <component id="timeslotCount" type="Hidden">
> <binding name="value" expression='timeslotCount'/>
> </component>
>
> </page-specification>
> --
>
> [EMAIL PROTECTED]
>
> --
> http://fastmail.fm - Access your email from home and the web
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Tapestry-developer mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/tapestry-developer
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer