public WOComponent createObjectAction() {
WOComponent nextPage = context().page();
// if creationDelegate binding is provided then just call the delegate with the right params.
// delegate is responsible for making sure the right page is returned after creating hte object.
if (useCreationDelegate()) {
EOEnterpriseObject obj = masterObjectKeyPathForCreationDelegate();
// defaults to object(), if masterObjectKeyPath is not provided
obj = (obj == null) ? object() : obj;
String relationshipName = relationshipName();
// defaults to key(), if the relationshipName binding is not provided
relationshipName = relationshipName == null ? key () : relationshipName;
nextPage = createObjectDelegate().create(obj, (String) valueForBinding ("destinationEntityName"), relationshipName);
}
else {
String editRelationshipConfigurationName = (String)valueForBinding("editRelationshipConfigurationName");
if(editRelationshipConfigurationName != null && editRelationshipConfigurationName.length() > 0) {
nextPage = D2W.factory().pageForConfigurationNamed(editRelationshipConfigurationName, session());
if(nextPage instanceof EditRelationshipPageInterface) {
EditRelationshipPageInterface epi = (EditRelationshipPageInterface)nextPage;
epi.setMasterObjectAndRelationshipKey(object(), key());
epi.setNextPage(context().page());
} else if(nextPage instanceof EditPageInterface) {
Object value = d2wContext().valueForKey("useNestedEditingContext");
boolean createNestedContext = ERXValueUtilities.booleanValue(value);
EOEnterpriseObject object = ERXEOControlUtilities.editableInstanceOfObject(object(), createNestedContext);
EOEditingContext ec = object.editingContext();
ec.lock();
try {
EOEnterpriseObject eo = ERXEOControlUtilities.createAndAddObjectToRelationship(ec, object, key(), (String)valueForBinding("destinationEntityName"), null);
EditPageInterface epi = (EditPageInterface)nextPage;
epi.setObject(eo);
epi.setNextPage(context().page());
} finally {
ec.unlock();