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

Reply via email to