Hi all,
I am making a web store. The store will have domain classes like "Item", and these will need a different "display" or "view" depending on where they are shown. For example, one view will be to customers so it will show things like pictures and descriptions. Another view will be for administration so it will be for editing this information, or creating new items. What is the best way to do this with Magritte? I know you have like the "description" method that makes the whole component view, and I seem to recall that you can change the name of that method, so I was wondering if I could have several such methods and use the one I want depending on where I am displaying the object? Thanks for any help you can provide, Jason _______________________________________________ SmallWiki, Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Doah, silly me. It was explained in Ramon's latest blog entry [1]. I
even had that very page open when I sent this question. :) [1] http://onsmalltalk.com/programming/smalltalk/using-magritte-with-seaside/ On 9/13/07, Jason Johnson <[hidden email]> wrote: > Hi all, > > I am making a web store. The store will have domain classes like > "Item", and these will need a different "display" or "view" depending > on where they are shown. For example, one view will be to customers > so it will show things like pictures and descriptions. Another view > will be for administration so it will be for editing this information, > or creating new items. > > What is the best way to do this with Magritte? I know you have like > the "description" method that makes the whole component view, and I > seem to recall that you can change the name of that method, so I was > wondering if I could have several such methods and use the one I want > depending on where I am displaying the object? > > Thanks for any help you can provide, > Jason > _______________________________________________ SmallWiki, Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
In reply to this post by Jason Johnson-5
> I am making a web store. The store will have domain classes like
> "Item", and these will need a different "display" or "view" depending > on where they are shown. For example, one view will be to customers > so it will show things like pictures and descriptions. Another view > will be for administration so it will be for editing this information, > or creating new items. > > What is the best way to do this with Magritte? I know you have like > the "description" method that makes the whole component view, and I > seem to recall that you can change the name of that method, so I was > wondering if I could have several such methods and use the one I want > depending on where I am displaying the object? There are different ways to do this and people have posted different solutions to this very problem to the list (check out the archive). The approach I am using most of the time (you can see it for example in Pier) is the following one: - Sending #description to an object returns all the available descriptions of this object. This is what Magritte does by default. - To create separate sub-sets of descriptions I tag them using the property framework. So for example I define my descriptions like: SomeDescription new ... propertyAt: #reported put: true; propertyAt: #visitor put: false; propertyAt: #administrator put: true; ... To make the code look nicer, you would create helper method for each tag as a class extension to MADescription. - Now to create a view with the elements for a 'visitor' I would write code like this: description := aModel description select: [ :each | each propertyAt: #visitor ifAbsent: [ false ] ]. component := description asComponentOn: aModel. Again with the help of some dedicated helper methods you can make your code look much simpler. This is just the full implementation to communicate the general idea. HTH, Lukas -- Lukas Renggli http://www.lukas-renggli.ch _______________________________________________ SmallWiki, Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
> There are different ways to do this and people have posted different > solutions to this very problem to the list (check out the archive). > The approach I am using most of the time (you can see it for example > in Pier) is the following one: > Another solution is to use a custom builder, see Magritte-CustomBuilder (currently in the pieraddons repository). Use (and hence initialize) your custom builder like so: MyClass-class-#mgViewActions ^ (MACustomDescriptionBuilder prefix: #mgViewActions) for: self This will work exactly as a standard builder, so results are cached as normal. It is faster and more efficient than the normal builder dues to a selectors lookup optimization (it stops looking at Object class, and doesnt go any higher, thus avoiding building and searching sets with thousands of entries) As you can see the hardest part of this solution is to come up with a decent method prefix as an alternative to #description! Having used this for a while, I think it works quite well. However, unless I can come up with some better naming conventions, I am thinking of reverting to the method which Lukas describes. i.e. define MADescription-#beViewAction ^ self propertyAt: #isViewAction put: true MADescription-isViewAction ^ self propertyAt: #isViewAction ifAbsent: false and MyClass-class-#viewActions ^ self description select: [ :each | each | isViewAction ]. best regards Keith _______________________________________________ SmallWiki, Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Yea thanks Keith and Lukas. I will play around with these to see what
fits my problem best. On 9/13/07, Keith Hodges <[hidden email]> wrote: > > > There are different ways to do this and people have posted different > > solutions to this very problem to the list (check out the archive). > > The approach I am using most of the time (you can see it for example > > in Pier) is the following one: > > > Another solution is to use a custom builder, see Magritte-CustomBuilder > (currently in the pieraddons repository). > > Use (and hence initialize) your custom builder like so: > > MyClass-class-#mgViewActions > > ^ (MACustomDescriptionBuilder prefix: #mgViewActions) for: self > > This will work exactly as a standard builder, so results are cached as > normal. It is faster and more efficient than the normal builder dues to > a selectors lookup optimization (it stops looking at Object class, and > doesnt go any higher, thus avoiding building and searching sets with > thousands of entries) > > As you can see the hardest part of this solution is to come up with a > decent method prefix as an alternative to #description! > > Having used this for a while, I think it works quite well. However, > unless I can come up with some better naming conventions, I am thinking > of reverting to the method which Lukas describes. i.e. define > > MADescription-#beViewAction > ^ self propertyAt: #isViewAction put: true > > MADescription-isViewAction > ^ self propertyAt: #isViewAction ifAbsent: false > > and > > MyClass-class-#viewActions > ^ self description select: [ :each | each | isViewAction ]. > > > best regards > > Keith > > > > > > > > > > _______________________________________________ > SmallWiki, Magritte, Pier and Related Tools ... > https://www.iam.unibe.ch/mailman/listinfo/smallwiki > _______________________________________________ SmallWiki, Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Free forum by Nabble | Edit this page |