Multiple copies of the same component on a page

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

Multiple copies of the same component on a page

Paul DeBruicker
Hi,

I have a component that I would like to render a variable number of
times on a page with slightly different contents each time it is
rendered.  I have an ordered collection that contains the different
content for each instance of the component.  An example of what I'd like
to do is the following:

I have a set of clients. Each client has a different set of assets in
their portfolio, and has a different number of assets in their
portfolio. On one page,  I'd like to display a price graph for each of
the assets in the portfolio for the time the client has held the asset.
  Since the timespan that the assets have been held will be different
for each client, the graphs should be independent.  My component will
get the time series of prices and plot it for an asset for the
appropriate time period.

What I have tried is this:

aPortfolio do: [:each | plot := PDAssetGraph new asset: each.].

PDAssetGraph's renderContentOn: method coordinates the collection and
ploting of the data. But my use of do: above just leaves me with a graph
of the last asset in the collection on my page.  How can I display and
keep all the intermediate graphs?  It seems to be pulling the data in
for them and is probably preparing the graphs as well, but only
rendering the last one.

Thanks for any guidance you can provide.

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

Re: Multiple copies of the same component on a page

Bob Nemec
Paul DeBruicker wrote
aPortfolio do: [:each | plot := PDAssetGraph new asset: each.].
You could use an instance variable to hold the collection of PDAssetGraph instances, which you answer as the children for the parent component.

self graphs: (aPortfolio collect: [:each | PDAssetGraph new asset: each])
Bob Nemec
Reply | Threaded
Open this post in threaded view
|

Re: Multiple copies of the same component on a page

Julian Fitzell-2
In reply to this post by Paul DeBruicker
You don't show what you are doing with "plot" so I don't know how you
are rendering it.

You could do something like:

aPortfolio do: [:each | html render: (PDAssetGraph new asset: each) ]

But Components are supposed to be persistent. So if you don't need
them to persist you should not use Components at all: just create an
object (in 2.9 you'd probably subclass WAPainter but in 2.8 it can
just be a subclass of Object) that responds to #renderOn: and pass
that into #render:. Then the above pattern works fine.

If you want to use Components, you should keep around the instances
between rendering passes. A good way is to use a dictionary:

aPortfolio do: [:each | html render: (theGraphs at: each ifAbsentPut:
(PDAssetGraph new asset: each)) ]

then you can return "theGraphs values" in your #children method.

I just blogged about how to choose whether to use a Component:
http://blog.fitzell.ca/2009/05/when-to-use-seaside-component.html
Perhaps that will help you decide.

Julian

On Mon, May 11, 2009 at 10:33 AM, Paul DeBruicker <[hidden email]> wrote:

> Hi,
>
> I have a component that I would like to render a variable number of times on
> a page with slightly different contents each time it is rendered.  I have an
> ordered collection that contains the different content for each instance of
> the component.  An example of what I'd like to do is the following:
>
> I have a set of clients. Each client has a different set of assets in their
> portfolio, and has a different number of assets in their portfolio. On one
> page,  I'd like to display a price graph for each of the assets in the
> portfolio for the time the client has held the asset.  Since the timespan
> that the assets have been held will be different for each client, the graphs
> should be independent.  My component will get the time series of prices and
> plot it for an asset for the appropriate time period.
>
> What I have tried is this:
>
> aPortfolio do: [:each | plot := PDAssetGraph new asset: each.].
>
> PDAssetGraph's renderContentOn: method coordinates the collection and
> ploting of the data. But my use of do: above just leaves me with a graph of
> the last asset in the collection on my page.  How can I display and keep all
> the intermediate graphs?  It seems to be pulling the data in for them and is
> probably preparing the graphs as well, but only rendering the last one.
>
> Thanks for any guidance you can provide.
>
> Paul
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside