Dear all,
Adding new objects in Aida is quite a common pattern, so let me explain how I usually do that, based on tutorial http://www.aidaweb.si/tutorial.html Task: we have AddressBook and Address. We can look at the list of addresses and each address by clicking on the link and viewing that address in a separate webpage. Now we'd like to add a new address. Solution in brief: 1. add an 'Add new address' button to the addresses page 2. implement action method to add new address 3. here create new Address object and redirect to its #new view 4. in #viewNew just call #viewEdit of Address object 5. in #viewEdit add button with action #save 6. implement action method #actionNewSave 7. here finally add the new object to its parent 8. optionally change its Url to prefered one 9. redirect to main view of new object Detailed solution: ADemoAddressBookApp>>viewMain | e | e := WebElement new. e addTextH1: 'Address book'. e addButtonText: 'Add new address' action: #add ... ADemoAddressBookApp>>actionMainAdd self redirectTo: (ADemoAddress new parent: self observee) view: #new ADemoAddressApp>>viewNew self viewEdit ADemoAddressApp>>viewEdit | e | e := WebElement new. ... "edit form" e addButtonText: 'Save' action: #save ... ADemoAddressApp>>actionNewSave self observee parent add: self observee. self site urlResolver changeToPreferedURL: self observee. self redirectToView: #main Comments: This pattern works only if child object has a back reference to its parent (usually in instvar #parent) As you can see in last action method, we change Url to become a prefered one at that time, that is at time of adding object to its parent. Why now? Because we entered the contents of object before adding it and this content is usually needed for composition of prefered Url. Also note that viewNew is reusing viewEdit, which is needed for later editing the object anyway. But action method name must still be composed as #actionNewSave ! Hope this clarifies that part a bit. Maybe it seems a bit complicated from a first sight, but it is quite simple and logical at the end. Just think in domain of MVC al the time! Janko -- Janko Mivšek AIDA/Web Smalltalk Web Application Server http://www.aidaweb.si _______________________________________________ Aida mailing list [hidden email] http://lists.aidaweb.si/mailman/listinfo/aida |
On Fri, Jun 6, 2008 at 10:11 AM, Janko Mivšek <[hidden email]> wrote:
Comments: I am happy to see that I have been doing this essentially correct! I have NOT been worrying about preferedUrl's yet, though, because my model keeps shifting around. At first I was naming my "parent" reference according to what type of object it was, but now I can see that it is important enough to maybe put it in a base class from which my Domain Model objects are referenced from. Thanks... Rob _______________________________________________ Aida mailing list [hidden email] http://lists.aidaweb.si/mailman/listinfo/aida |
Free forum by Nabble | Edit this page |