Hey all,
I was working on adding basic add/delete functionality to my app, but am having difficulty getting my delete functionality to work. I'm pretty sure it's something pretty stupid or obvious, as I've done this before and certainly have plenty of examples around...but I can't for the life of me figure out what I'm doing wrong.
Basically I'm getting an array out-of-bounds exception after trying to delete an object in an Ajax action: [2009-2-18 14:35:38 PST] <WorkerThread3> java.lang.IllegalArgumentException: Index (2) out of bounds [0, 1] at com.webobjects.foundation.NSArray.objectAtIndex(NSArray.java:395) at com.webobjects.eocontrol._EOCheapCopyMutableArray.objectAtIndex(_EOCheapCopyMutableArray.java:110) at er.extensions.components._private.ERXWORepetition$Context.objectAtIndex(ERXWORepetition.java:146) at er.extensions.components._private.ERXWORepetition._prepareForIterationWithIndex(ERXWORepetition.java:243) at er.extensions.components._private.ERXWORepetition.invokeAction(ERXWORepetition.java:444) at com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WODynamicGroup.java:105) at com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicGroup.java:115) ...
Here's the basic component html:
<wo:AjaxUpdateContainer id = "ActivitiesListContainer"> <wo:form name = "ActivitiesList" multipleSubmit = "true"> <div id="activities_list"> <table> <tr> <th class="activities_list_delete_column"> </th> <th class="activities_list_name_column">Name</th> <th class="activities_list_date_column">Created</th> </tr> <wo:ERXWORepetition list = "[currentActivities]" item = "[anActivity]"> <tr> <td class="activities_list_delete_column"><wo:AjaxSubmitButton action = "[deleteActivity]" button="true" value = "Delete" updateContainerID = "ActivitiesListContainer" /></td> <td class="activities_list_name_column"><wo:string value="[anActivity.name]" /></td> <td class="activities_list_date_column"><wo:string value="[anActivity.createdAt]" /></td> </tr> </wo:ERXWORepetition> </table> </div> <wo:AjaxSubmitButton action = "[addActivity]" id = "add_activity_button" value = "Add Activity" updateContainerID = "ActivitiesListContainer" /> </wo:form> </wo:AjaxUpdateContainer>
And here's the (hopefully) relevant code:
public class MWActivitiesList extends ERXComponent {
public Activity anActivity;
public MWActivitiesList(WOContext context) { super(context); }
public NSArray<Activity> currentActivities() { Session session = (Session)session(); Account user = session.user(); return user.activities(); }
public WOActionResults deleteActivity() { Session session = (Session)session(); Account user = session.user(); EOEditingContext ec = user.editingContext();
user.deleteActivitiesRelationship(anActivity);
try { ec.saveChanges(); } catch ( Exception e ) { log.debug("Exception raised deleting activity: " + e.toString()); e.printStackTrace(); }
return null; } }
Based on my logging, and looking at method calls, it looks almost like the ERXWORepitition is trying to access outside the bounds of the array, but doing so without even calling currentActivities() when updating the AjaxUpdateContainer. Also, strangely enough deleting from the END of the array works fine, it's only deletes from the beginning or middle that fail.
The component is pretty basic. The object model is pretty basic (generated in Eclipse from the EOModel). Nothing particularly tricky going on anywhere. Driving...me...crazy.
FYI, the Wonder build I'm using is 5.0.0.8421.
- Leif
---------- Leif Harrison Senior Engineer - Ubermind, Inc.
|