Skip to content

Commit

Permalink
Fixes several issues with ERMD2WEditToOneTypeAhead:
Browse files Browse the repository at this point in the history
 * when used in an embedded to-many context, the previously selected object would remain selected on a subsequent invocation on another related object
 * caused premature display of validation errors due to the use of the parent's update container
 * no way to set a fetch limit
 * typo in key name (typeAheadMinimumCharaceterCount)

The typo fix may affect existing projects if a rule with a value other than "3" was created.
  • Loading branch information
fbarthez committed Nov 14, 2015
1 parent 9c62945 commit 602106d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="ERMD2WEditToOneTypeAhead">
<webobject name = "ERMD2WEditToOneTypeAhead">
<div class="ToOneTypeAheadFieldWrapper">
<webobject name = "AjaxAutoComplete"/>
<webobject name="SearchTermSelected"/>
Expand All @@ -16,4 +16,4 @@
</webobject>
</ul>
</div>
</div>
</webobject>
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
ERMD2WEditToOneTypeAhead : AjaxUpdateContainer {
id = updateContainerID;
class = "ToOneTypeAheadFieldUC";
}

SearchTermSelected : AjaxSubmitButton {
updateContainerID = d2wContext.idForMainContainer;
functionName = searchTermSelectedFunctionName;
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/D2W/ERModernDirectToWeb/Resources/d2w.d2wmodel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.BooleanAssignment"; "keyPath" = "useAjaxControls"; "value" = "true"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.Assignment"; "keyPath" = "displayKeyForEntity"; "value" = "entity.name"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.BooleanAssignment"; "keyPath" = "includeOptionalForm"; "value" = "true"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.Assignment"; "keyPath" = "typeAheadMinimumCharaceterCount"; "value" = "3"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.Assignment"; "keyPath" = "typeAheadMinimumCharacterCount"; "value" = "3"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.BooleanAssignment"; "keyPath" = "useAjaxControlsWhenEmbedded"; "value" = "false"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "rhs" = {"class" = "com.webobjects.directtoweb.Assignment"; "keyPath" = "typeAheadSearchTemplate"; "value" = "*@@searchValue@@*"; }; },
{"author" = "0"; "class" = "com.webobjects.directtoweb.Rule"; "lhs" = {"class" = "com.webobjects.eocontrol.EOKeyValueQualifier"; "key" = "pageConfiguration"; "selectorName" = "isLike"; "value" = "*Embedded*"; }; "rhs" = {"class" = "com.webobjects.directtoweb.BooleanAssignment"; "keyPath" = "useAjaxControls"; "value" = "true"; }; },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
0 : *true* => useAjaxControls = "true" [com.webobjects.directtoweb.BooleanAssignment],
0 : *true* => displayKeyForEntity = "entity.name" [com.webobjects.directtoweb.Assignment],
0 : *true* => includeOptionalForm = "true" [com.webobjects.directtoweb.BooleanAssignment],
0 : *true* => typeAheadMinimumCharaceterCount = "3" [com.webobjects.directtoweb.Assignment],
0 : *true* => typeAheadMinimumCharacterCount = "3" [com.webobjects.directtoweb.Assignment],
0 : *true* => useAjaxControlsWhenEmbedded = "false" [com.webobjects.directtoweb.BooleanAssignment],
0 : *true* => typeAheadSearchTemplate = "*@@searchValue@@*" [com.webobjects.directtoweb.Assignment],
0 : pageConfiguration like '*Embedded*' => useAjaxControls = "true" [com.webobjects.directtoweb.BooleanAssignment],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* @d2wKey restrictingFetchSpecification - name of the model FetchSpec supplies the list of objects to be searched from (keyWhenRelationship is NOT an attribute) or that additionally qualifies the fetch
* @d2wKey extraRestrictingQualifier - an additional qualifier (defined in the rules) that additionally qualifies the search
* @d2wKey typeAheadSearchTemplate - a template that wraps the searchValue (for the inclusion of pre/post wildcards: i.e: "*@@searchValue@@*" )
* @d2wKey typeAheadMinimumCharaceterCount - minimum number of characters before a search is performed
* @d2wKey typeAheadMinimumCharacterCount - minimum number of characters before a search is performed
* @d2wKey sortKey
* @d2wKey isMandatory
* @d2wKey propertyKey
Expand All @@ -67,7 +67,9 @@

public class ERMD2WEditToOneTypeAhead extends ERDCustomEditComponent {

public interface Keys extends ERDCustomEditComponent.Keys {
private static final long serialVersionUID = 1L;

public interface Keys extends ERDCustomEditComponent.Keys {
public static final String newButtonLabel = "newButtonLabel";
public static final String classForNewObjButton = "classForNewObjButton";
public static final String pageConfiguration = "pageConfiguration";
Expand All @@ -80,7 +82,8 @@ public interface Keys extends ERDCustomEditComponent.Keys {
public static final String typeAheadSearchTemplate = "typeAheadSearchTemplate";
public static final String extraRestrictingQualifier = "extraRestrictingQualifier";
public static final String keyWhenRelationship = "keyWhenRelationship";
public static final String typeAheadMinimumCharaceterCount = "typeAheadMinimumCharaceterCount";
public static final String typeAheadMinimumCharacterCount = "typeAheadMinimumCharacterCount";
public static final String fetchLimit = "fetchLimit";
}

public static Logger log = Logger.getLogger(ERMD2WEditToOneTypeAhead.class);
Expand All @@ -107,10 +110,13 @@ public ERMD2WEditToOneTypeAhead(WOContext context) {
super(context);
}

@SuppressWarnings("rawtypes")
@Override
public void awake() {
NSNotificationCenter.defaultCenter().addObserver(this, new NSSelector("relatedObjectDidChange", ERXConstant.NotificationClassArray), ERMDActionButton.BUTTON_PERFORMED_DELETE_ACTION, null);
super.awake();
// make sure we don't display a previous search value
_searchValue = null;
}

@Override
Expand All @@ -120,8 +126,7 @@ public void sleep() {
}

/**
* Called when an {@link ERMDActionButton} changes the related object. Nulls
* {@link #_searchValue} which in turn lets it rebuild on the next display
* Called when an {@link ERMDActionButton} changes the related object.
*/
@SuppressWarnings("unchecked")
public void relatedObjectDidChange(NSNotification notif) {
Expand All @@ -130,7 +135,6 @@ public void relatedObjectDidChange(NSNotification notif) {
Object key = userInfo.valueForKey("propertyKey");
EOEnterpriseObject obj = (EOEnterpriseObject)userInfo.valueForKey("object");
if (propertyKey() != null && propertyKey().equals(key) && ERXEOControlUtilities.eoEquals(object(), obj)) {
_searchValue = null;
_currentSelection = null;
}
}
Expand All @@ -142,6 +146,14 @@ public boolean synchronizesVariablesWithBindings() {
return false;
}

/** Used by stateful but non-synching subclasses */
@Override
public void resetCachedBindingsInStatefulComponent() {
super.resetCachedBindingsInStatefulComponent();
// make sure we clear a previous selection
_currentSelection = null;
}

/**
* Value displayed by the AjaxAutoFill field, if nothing is entered in the
* field it will return either the kvc value of 'keyWhenRelationship' on the related
Expand Down Expand Up @@ -221,11 +233,10 @@ public WOActionResults selectObject() {
/**
* Action called when user clicks the Add button
*/
@SuppressWarnings("unchecked")
public WOActionResults addObject() {
String currentPageConfiguration = stringValueForBinding(Keys.pageConfiguration);

NSDictionary extraValues = currentPageConfiguration != null ? new NSDictionary(currentPageConfiguration, Keys.pageConfiguration) : null;
NSDictionary<String, String> extraValues = currentPageConfiguration != null ? new NSDictionary<String, String>(currentPageConfiguration, Keys.pageConfiguration) : null;
String createPageConfigurationName = (String)ERDirectToWeb.d2wContextValueForKey(Keys.createConfigurationName, destinationEntityName(), extraValues);

EditPageInterface epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed(createPageConfigurationName, session());
Expand Down Expand Up @@ -275,6 +286,11 @@ public NSArray<EOEnterpriseObject> destinationObjectsWithQualifier(EOQualifier q
qual = ERXQ.and(qual, restrictingFetchSpec().qualifier());
}
EOFetchSpecification fetchSpec = new EOFetchSpecification(destinationEntityName(), qual, orderings);
if (!ERXStringUtilities.stringIsNullOrEmpty((String) d2wContext()
.valueForKey(Keys.fetchLimit))) {
fetchSpec.setFetchLimit(Integer.valueOf((String) d2wContext()
.valueForKey(Keys.fetchLimit)));
}
fetchSpec.setIsDeep(true);
EOEditingContext ec = ERXEC.newEditingContext();
result = ec.objectsWithFetchSpecification(fetchSpec);
Expand Down Expand Up @@ -330,8 +346,7 @@ public NSArray<EOEnterpriseObject> allItems() {

public EOFetchSpecification restrictingFetchSpec() {
if (_restrictingFetchSpec == null) {

_restrictingFetchSpec = EOModelGroup.defaultGroup().fetchSpecificationNamed(restrictingFetchSpecificationName(), destinationEntityName());;
_restrictingFetchSpec = EOModelGroup.defaultGroup().fetchSpecificationNamed(restrictingFetchSpecificationName(), destinationEntityName());
}
return _restrictingFetchSpec;
}
Expand Down Expand Up @@ -366,7 +381,7 @@ public EOQualifier extraQualifier() {

public Integer minimumCharacterCount() {
if (_minimumCharacterCount == null) {
_minimumCharacterCount = ERXValueUtilities.IntegerValueWithDefault(stringValueForBinding(Keys.typeAheadMinimumCharaceterCount), 1);
_minimumCharacterCount = ERXValueUtilities.IntegerValueWithDefault(stringValueForBinding(Keys.typeAheadMinimumCharacterCount), 1);
}
return _minimumCharacterCount;
}
Expand All @@ -384,8 +399,8 @@ public Object restrictedChoiceList() {
return valueForKeyPath(restrictedChoiceKey);
String fetchSpecName = stringValueForBinding(Keys.restrictingFetchSpecification);
if(fetchSpecName != null) {
EORelationship relationship = ERXUtilities.relationshipWithObjectAndKeyPath(object(),
(String)d2wContext().valueForKey(Keys.propertyKey));
EORelationship relationship = ERXUtilities.relationshipWithObjectAndKeyPath(
(EOEnterpriseObject) object(), propertyKey());
return EOUtilities.objectsWithFetchSpecificationAndBindings(object().editingContext(), relationship.destinationEntity().name(),fetchSpecName,null);
}
return null;
Expand All @@ -407,12 +422,21 @@ public String newButtonLabel() {

// AJAX IDs

public String searchTermSelectedFunctionName() {
if (_safeElementID == null) {
_safeElementID =ERXStringUtilities.safeIdentifierName(context().elementID());
}
return "ermdtorlu_" + _safeElementID + "CompleteFunction";
}
public String updateContainerID() {
if (_safeElementID == null) {
_safeElementID = ERXStringUtilities.safeIdentifierName(this.context()
.elementID());
}
return "PCUC_" + _safeElementID;
}

public String searchTermSelectedFunctionName() {
if (_safeElementID == null) {
_safeElementID = ERXStringUtilities.safeIdentifierName(this.context()
.elementID());
}
return "ermdtorlu_" + _safeElementID + "CompleteFunction";
}

public String searchTermSelectedFunction() {
return "function(e) { " + searchTermSelectedFunctionName() + "(); }";
Expand Down

0 comments on commit 602106d

Please sign in to comment.