Skip to content

Commit

Permalink
correct selection on ERXDisplayGroup
Browse files Browse the repository at this point in the history
Last changes to ERXDisplayGroup resulted in incorrect selection when using batching as in that case _displayedObjects and displayedObjects() give you different data. This patch uses reflection instead of altering the newSelection array for performance reasons.
  • Loading branch information
darkv committed Feb 21, 2014
1 parent 2f06f7a commit a7593e5
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package er.extensions.appserver;

import java.lang.reflect.Field;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
Expand All @@ -14,6 +16,8 @@
import com.webobjects.eocontrol.EOSortOrdering;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSDictionary;
import com.webobjects.foundation.NSForwardException;
import com.webobjects.foundation.NSMutableArray;
import com.webobjects.foundation.NSMutableDictionary;
import com.webobjects.foundation.NSMutableSet;
import com.webobjects.foundation.NSSet;
Expand All @@ -34,6 +38,8 @@
* @param <T> data type of the displaygroup's objects
*/
public class ERXDisplayGroup<T> extends WODisplayGroup {
private Field displayedObjectsField;

/**
* Do I need to update serialVersionUID?
* See section 5.6 <cite>Type Changes Affecting Serialization</cite> on page 51 of the
Expand All @@ -46,6 +52,16 @@ public class ERXDisplayGroup<T> extends WODisplayGroup {

public ERXDisplayGroup() {
super();
try {
displayedObjectsField = WODisplayGroup.class.getDeclaredField("_displayedObjects");
displayedObjectsField.setAccessible(true);
}
catch (SecurityException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
catch (NoSuchFieldException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
}

/**
Expand Down Expand Up @@ -202,7 +218,19 @@ public void setSelectedObjects(NSArray objects) {
} else {
// jw: don't call super as it does not call setSelectionIndexes as advertised in its
// javadocs and thus doesn't invoke events on the delegate
NSArray<Integer> newSelection = _NSArrayUtilities.indexesForObjectsIndenticalTo(displayedObjects(), objects);
// we need to access the private field _displayedObjects directly as we would get
// wrong indexes when calling displayedObjects()
NSMutableArray displayedObjects;
try {
displayedObjects = (NSMutableArray) displayedObjectsField.get(this);
}
catch (IllegalArgumentException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
catch (IllegalAccessException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
NSArray<Integer> newSelection = _NSArrayUtilities.indexesForObjectsIndenticalTo(displayedObjects, objects);
setSelectionIndexes(newSelection);
}
}
Expand Down

0 comments on commit a7593e5

Please sign in to comment.