Re: Components and sub-components
Re: Components and sub-components
- Subject: Re: Components and sub-components
- From: David Griffith <email@hidden>
- Date: Thu, 06 Nov 2003 03:00:52 +0100
Chuck,
Thanks for that. I have finally realised that subclassing was not the
option :-) So now, can you point me to some good documentation and
tutorials on components and communication between them... I have gone
through everything I can find and none of them have been much help at all.
I have seen mention of bindings between components but have no idea how to
use them.
Regards,
Dave.
> More comments on where you have left the straight and true :-) path:
>
>
> At 07:59 PM 05/11/2003 +0100, David Griffith wrote:
>>
>> I will try and describe this as clearly as possible, if anyone could please
>> tell me if this is the correct approach or if I am missing something...
>>
>> I have a component ShowPhoto - it contains a header jpg, a menu bar, a table
>> with photo and details from a database and a search box at the bottom.
>>
> I would make these components:
> Header - shows header jpg, whatever else should go at top
> MenuBar - show only the menu
> Photo - table with photo and details
> PhotoSearch - searching functions
>
>
>> There is a lot of code in the ShowPhoto component relating to the current
>> photo, getting info from the database etc.
>>
> erk! Most of this should go in the enterprise object. The WOComponent is
> about display not database access and image manipulation. Your goals at
> the UI level should be two-fold:
> 1. Only code directly related to that specific representation in that
> specific UI
> 2. As little code as possible. None is best. :-)
>
> Move all the code you can to the photo EO. Move the rest to the Photo
> component.
>
>> I also have a MenuBar component which I have inserted into the ShowPhoto
>> page as a custom WebObject. It is not a subclass of ShowPhoto and it works
>> well.
>>
>> The search box at the bottom again is the same, it9s inserted as a custom
>> WebObject and is not a subclass of ShowPhoto.
>>
> That is as it should be.
>
>
>> Now, I wanted to have two templates which would display the photo and text
>> in a different way, but would leave everything else on the page as is.
>>
> Think composing pages of smaller, reusable pieces.
>
>
>> There are also buttons on the page to move the next photo and previous, and
>> these generally work the same on every ShowPhoto page and use methods from
>> ShowPhoto.
>>
> This should probably be in the Photo component I mentioned above. Or
> broken out into a PhotoNavigation component and used in Photo.
>
>
>> I created two components templHoriz and templVert. These are set to extend
>> ShowPhoto (as subclasses) as I want them to have access to the methods and
>> variables of ShowPhoto.
>> (I assume this is what I should do, tell me if not!).
>>
> This will not let them communicate if that is what you are expecting. Do
> templHoriz and templVert have the same functionality as ShowPhoto but a
> different UI? If so, then sub-classing is good.
>
>
>> Then I have conditionally inserted the templates into ShowPhoto
>> based on a boolean. Ie. There are two custom WebObjects on ShowPhoto, which
>> will display depending on the boolean.
>>
> No, no, that sounds wrong. Sub-classing is not going to let them
> communicate values (data), only share functionality (code).
>
>
>> This all works lovely except that I am finding some very weird behaviour
>> with variables. I assumed from this setup that the templates would be able
>> to use and modify all the variables of ShowPhoto.
>>
> They can, but not like you are imagining. If ShowPhoto has a variable foo
> then so does templHoriz and templVert. ***However*** they are different
> foos pointing to three different places in memory.
>
>
>> The photos are displayed based on an array which is currently a session
>> variable.
>>
> Probably not a good design decision.
>
>
>> I have a WOPopUpButton which allows the user to select a value.
>> This bit is a little tricky and after hours last night I finally discovered
>> that the selection9 binding is only set when the form is submitted.
> Nothing the user does has any effect on your application until the form is
> submitted or a new URL is requested (which pretty much amounts to the same
> thing).
>
>> So I
>> wrapped the button in a form and set the onChange9 binding to submit it.
>> The submit does a method in ShowPhoto called refreshPage9. Simply, it sets
>> a boolean in ShowPhoto which will indicate whether or not to include some
>> javascript in the header the next time the page loads.
>>
> That sounds correct.
>
>
>> The anomale I have encountered is that when this value is set in ShowPhoto,
>> it does not appear to maintain this value when the page is refreshed.
> That is because it is changing one copy and you are trying to read this
> from another. Use Binding Syncronization not inheritance to achieve what
> you want.
>
>
>> I.e.
>> The refreshPage method sets it to YES (for example) and I have confirmed
>> that at that point it is YES. Then it returns null to refresh the page but
>> the results indicate that the value was NO. However in the template
>> (subclass of ShowPhoto) the value appears to be correct as another item on
>> that page DOES display as a result of the YES (which is what I expected).
>>
> That is because it is looking at the right copy! :-)
>
>
>> So how can the value have two different values at different stages when
>> there is nothing to change it in between?
> Ah grasshopper. There are two values, not the one that you think you see.
>
>
>> The only reason I can think of is
>> SCOPE, although I can9t see how. So, I moved that boolean value into the
>> session class instead and it works fine. But there are others that don9t
>> (because I haven9t moved them to the Session class and I don9t see why they
>> should be there).
>>
> They should not. You are using the wrong technique.
>
>
>> Can anyone (if you can make sense of this) see what the problem is here? I
>> would be happy to go into a bit more detail directly if necessary as I am
>> concerned there might be a core flaw in my design and I don9t want to
>> continue working that way if it9s incorrect.
>>
> Maybe now is a good time to revisit the tutorials on building components.
> I fear you may have misunderstood something the first time around.
>
>
> Regards,
> Chuck
>
>
> --
>
> Chuck Hill email@hidden
> Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.