I have a possible solution to the puzzle at end of Chapter 12.2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

I have a possible solution to the puzzle at end of Chapter 12.2

Intrader Intrader
Thanks to Joachin Small World I have changed the code as follows:
1. Use cancelButton instead of submitButton in ConcatView.
2. Change the editContact as follows:
<code>
editContact: aContact
        (editor contact: aContact) onAnswer: [ :answer |
                answer
                ifFalse: [
                        self handleAnswer: false.
                        ] .
]
</code>

The code above works and the Cancel button works properly. I would like feedback
 as to the validity of the solution.

I had explored other solutions including:

1. Use of Magritte

2. Returning nil up the hierarchy on Cancel.

3. I had tried a variation of the solution suggested in Chapter 11.5, but that
solution suffers from problems inherent in the example of Chapter 11.5 (only
works when the the ContactViewList is rerendered). Removing the contact fails
because when the button is reclicked, the list no longer contains the contact.

P.S. This an old problem that had remained unsolved for me ( I posted the
problem before)

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: I have a possible solution to the puzzle at end of Chapter 12.2

Lukas Renggli
> Thanks to Joachin Small World I have changed the code as follows:
> 1. Use cancelButton instead of submitButton in ConcatView.
> 2. Change the editContact as follows:
> <code>
> editContact: aContact
>        (editor contact: aContact) onAnswer: [ :answer |
>                answer
>                ifFalse: [
>                        self handleAnswer: false.
>                        ] .
> ]
> </code>
>
> The code above works and the Cancel button works properly. I would like feedback
>  as to the validity of the solution.

Hard to tell from the context given (The code looks suspicious to
assign multiple onAnswer: handler). The cancel button works fine as
long as the form is not submitted multiple times, such as for
validation. The easiest and most stable solution is to edit a copy of
the contact and to replace it in the collection on success.

Lukas


>
> I had explored other solutions including:
>
> 1. Use of Magritte
>
> 2. Returning nil up the hierarchy on Cancel.
>
> 3. I had tried a variation of the solution suggested in Chapter 11.5, but that
> solution suffers from problems inherent in the example of Chapter 11.5 (only
> works when the the ContactViewList is rerendered). Removing the contact fails
> because when the button is reclicked, the list no longer contains the contact.
>
> P.S. This an old problem that had remained unsolved for me ( I posted the
> problem before)
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>



--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: I have a possible solution to the puzzle at end of Chapter 12.2

Intrader Intrader
Lukas Renggli <renggli <at> gmail.com> writes:


> Hard to tell from the context given (The code looks suspicious to
> assign multiple onAnswer: handler). The cancel button works fine as
> long as the form is not submitted multiple times, such as for
> validation. The easiest and most stable solution is to edit a copy of
> the contact and to replace it in the collection on success.
>
Thanks Lukas for your comment.
Sorry you found the posting to have lack of context. I am referencing Chapter
12.2 of Dynamic Web Development with Seaside. The end of the chapter states:
"Our simple implementation of IAddress>>editContact: will save changes even when
you press cancel. See Section 11.5 to understand how you can change this.".

I have coded my interpretation of what Chapter 11.5 means as follows:
<code>
editContact: aContact
    | copy |
    copy := aContact copy.
    (editor contact: copy) onAnswer: [ :answer |
        "copy has been updated - keep update if Save"
        answer
        ifTrue: [
            Contact removeContact: aContact; addContact: copy.
            "Problem: a reclick on Save aborts because contact is not in
 collection"
        ]
]
</code>
As you suggest the above code should replace the contact with the copy. I do not
yet have the proper coding for replacing the contact.

The solution suggested by Joachim uses `self handleAnswer: false`. This works. I
am seeking comment as to the approach and validity of relying on priority of the
cancel callback and use of #handleAnswer.




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: I have a possible solution to the puzzle at end of Chapter 12.2

Intrader Intrader
Fritz Schenk <intrader.intrader <at> gmail.com> writes:

>
> Lukas Renggli <renggli <at> gmail.com> writes:
>
> > Hard to tell from the context given (The code looks suspicious to
> > assign multiple onAnswer: handler). The cancel button works fine as
> > long as the form is not submitted multiple times, such as for
> > validation. The easiest and most stable solution is to edit a copy of
> > the contact and to replace it in the collection on success.
> >
Here is the code to edit a copy and then replace it in the collection.
<code>
editContact: aContact
        "overides - comment stating purpose of message"
       
        | copy contacts|
        contacts:= MyContact contacts.
        copy := aContact copy.
        (editor contact: copy) onAnswer: [ :answer |
                "copy has been updated"
                answer ifTrue: [contacts at: (contacts indexOf: aContact)
put: copy
                        ]
 ]
</code>


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside