should you be doing this with your EO?

a job for didInsert() ?




On Jul 30, 2013, at 12:05 PM, Theodore Petrosky <[email protected]> wrote:

> This is not directly a reply to David. I am about to try my hand at 
> implementing this in my app. 
> 
> David asks the sensible question if anyone thinks there is a better way to do 
> this. Maybe someone can chime in here.
> 
> Basically, in a D2W app with to Many relations, when you add a new 
> relationship object, and press the 'save' button, it doesn't call 
> saveChanges() on the EC. It is just added to the relationship and you must 
> complete the transaction or risk fire and brimstone.
> 
> The result I want would be that when you press the 'save' button in a 'Create 
> new embedded object', WO will actually save the object and relationship to 
> the backend.
> 
> Ted
> 
> On Jul 18, 2013, at 12:50 PM, David Holt <[email protected]> wrote:
> 
>> Hi Ted,
>> 
>> This is how I handled it. It isn't pretty and it was early days in my 
>> experience with D2W, so there may be a better way…
>> 
>> David
>> 
>> Rule
>> 
>> 101 : ((pageConfiguration = 'EditRelationshipEmbeddedAnswer' and 
>> parentPageConfiguration = 'EditTestItem') => branchChoices = 
>> ("_scoreOptionInline") [com.webobjects.directtoweb.Assignment]
>> 
>> BranchDelegate  
>> 
>> /**
>>    * Score the option
>>    * 
>>    * @return
>>    */
>>   public WOComponent _scoreOptionInline(WOComponent sender) {
>>     WOComponent nextPage;
>>     // Get the objects we need
>>     PossibleAnswer possibleAnswer = (PossibleAnswer) object(sender);
>> 
>>     // Create a new editing context and setup validation
>>     EOEditingContext newEc = 
>> ERXEC.newEditingContext(possibleAnswer.editingContext());
>>     newEc.revert();
>>     Person currentPerson = Person.currentUser(newEc);
>>     // Choose the option to be scored
>>     PossibleAnswer newAnswer = possibleAnswer.localInstanceIn(newEc);
>> 
>>     // Create  scoring object
>>     System.out.println("What is the value of the score? " + 
>> newAnswer.score() + " for " + newAnswer.answerDescription());
>>     EOQualifier qual = 
>> Score.PERSON.eq(currentPerson).and(Score.ANSWER.eq(newAnswer));
>>     if (newAnswer.aScore() != null) {
>>       System.out.println("We're populating an existing object " + 
>> newAnswer.score());
>>       nextPage = 
>> session(sender).navController().createScore(Score.fetchScore(newEc, qual));  
>>    //// See method in NavController below
>>     } else {
>>       Score newScore = Score.createScore(newEc, currentPerson, newAnswer);
>>       if (newAnswer instanceof ERXGenericRecord) {
>>         ((ERXGenericRecord) newAnswer).setValidatedWhenNested(false);
>>       }
>>       System.out.println("We're creating a new object " + newAnswer.score());
>>       nextPage = session(sender).navController().createaScoreScore(newScore);
>>     }
>> 
>>     return nextPage;
>>   }
>> 
>> 
>> NavigationController
>> 
>>   public WOComponent createScore(Score aScore) {
>>     EditPageInterface newEditPage = 
>> D2W.factory().editPageForEntityNamed(Score.ENTITY_NAME, session());
>>     newEditPage.setObject(aScore);
>>     newEditPage.setNextPageDelegate(new SaveBeforeReturning (
>>     // return to current page after saving new score
>>         session().context().page()));
>>     WOComponent nextPage = (WOComponent) newEditPage;
>>     return nextPage;
>>   }
>> 
>>   public class SaveBeforeReturning implements NextPageDelegate {
>> 
>>     public SaveBeforeReturning(WOComponent afterSaving) {
>>       // remember where to go after the save
>>       theRealNextPage = afterSaving;
>>     }
>> 
>>     private WOComponent theRealNextPage;
>> 
>>     // when the person hits save on the page
>>     // this method will be called
>> 
>>     public WOComponent nextPage(WOComponent sender) {
>>       // set up for branching based on whether the cancel button, or the save
>>       // button was pressed
>>       D2WPage page = (D2WPage) theRealNextPage;
>>       EOEnterpriseObject eo = page.object();
>>       // a null editing context means that the cancel button was pressed
>>       if (eo.editingContext() == null) {
>>         return theRealNextPage;
>>       }
>>       // otherwise, the save button was pressed
>>       else {
>>         eo.editingContext().saveChanges();
>>         return theRealNextPage;
>>       }
>>     }
>>   }
>> 
>> 
>> On 2013-07-18, at 8:29 AM, Theodore Petrosky <[email protected]> wrote:
>> 
>>> David,
>>> 
>>> How did you do this? I have been mucking around, but have not found a 
>>> solution.
>>> 
>>> playing with some Logs in the submitAction() method makes me realize that 
>>> the object need to be entered into the EC. I will keep playing.
>>> 
>>> Ted
>>> 
>>> 
>>> On Jul 12, 2013, at 12:27 PM, David Holt <[email protected]> wrote:
>>> 
>>>> The trade-off is that if you save the parent EC form the related EC, you 
>>>> may save an edit on the parent that the user is not expecting. In most 
>>>> cases I agree with you and I have implemented a true save on the related 
>>>> component to reduce the user confusion about the "double save".
>>>> 
>>>> 
>>>> On 2013-07-12, at 8:33 AM, Theodore Petrosky <[email protected]> wrote:
>>>> 
>>>>> when I create a new to-many object there is a button with a  label 
>>>>> 'Save'. I understood that this new object was inserted into the EC and I 
>>>>> had to click the save button at the bottom of my parent EO to actually 
>>>>> save the related object.
>>>>> 
>>>>> but of course there is a problem. If I add an object and immediately 
>>>>> click its delete button, my app throws a hissy-fit because the object can 
>>>>> not be deleted as it is not saved in the first place.
>>>>> 
>>>>> So the question is. when I create a new object, and click save, shouldn't 
>>>>> d2w do just that? saveChanges() on the EC?
>>>>> 
>>>>> this is the saveButton's action (from ERMODWizardCreationPage).
>>>>> /**
>>>>>  * Performs submit action. Overridden to reset the nested validation 
>>>>> setting on the
>>>>>  * object.
>>>>>  */
>>>>>  // FIXME - Is this needed here? davidleber
>>>>>  @Override
>>>>>  public WOComponent submitAction() throws Throwable {
>>>>>   WOComponent result = super.submitAction();
>>>>>   if (object() instanceof ERXGenericRecord) {
>>>>>      ((ERXGenericRecord)object()).setValidatedWhenNested(true);
>>>>>   }
>>>>>  return result;
>>>>> }
>>>>> 
>>>>> I keep following back the super.submitAction() to see what it does but 
>>>>> there is no implied saveChanges() anywhere that I can find.
>>>>> 
>>>>> 
>>>>> _______________________________________________
>>>>> Do not post admin requests to the list. They will be ignored.
>>>>> Webobjects-dev mailing list      ([email protected])
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>> https://lists.apple.com/mailman/options/webobjects-dev/programmingosx%40mac.com
>>>>> 
>>>>> This email sent to [email protected]
>>>> 
>>> 
>> 
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/jtayler%40oeinc.com
> 
> This email sent to [email protected]


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to