You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Malin Ljungh <ma...@gmail.com> on 2006/11/14 07:43:01 UTC

Text rotator component

I wish I had a tapestry component that would read a text file and randomly
output one of the rows.
Like a "quote rotator"... does anyone know if it exists out there or will I
have to write it myself?

If I'd write it myself... how would I do - any suggestions?
I suppose I'd wan't to read the file (which is small) in a static variable
so I only need to do this once per class loader?
How do I specify the asset file and how will my component find it...hmmm

Any help highly appreciated!

Malin

Re: Text rotator component

Posted by Malin Ljungh <ma...@gmail.com>.
Thank you Sam!
You have given me the obvious solution. Why complicate things?

Thanks :)

On 11/14/06, Sam Gendler <sg...@ideasculptor.com> wrote:
>
> depends on what kind of infrastructure you want.  In the simplest
> case, just hardcode a file path into a class, open it and read its
> contents in a static block, and then just access from an Insert
> component (<binding name="value"
> value="ognl:myFileReaderObject.randomLine"/>)
>
> One step up would be to place the filepath in a config file included
> with your webapp. Either stick it in a hivemind config as a parameter
> to a service object, do something similar with a spring
> application-context, or even push it into your servlet from the
> web.xml file.
>
> If you absolutely must have a component and the component really must
> be passed a data source at each render time, presumably because you
> want to be able to choose from many sources, I would just have your
> component receive a model object which adheres to some interface, then
> provide an instance of that class to your page via hivemind (or
> spring), and configure the filepath in the hivemind.spring config.
>
> It still seems easier to me to have some kind of service object which
> can provide a line of text at random, and then just insert the text
> into the page via an Insert component.  The only reason to make it a
> standalone component is if you need to wrap the text in some custom
> html, and that is simple enough.
>
> --sam
>
>
> On 11/13/06, Malin Ljungh <ma...@gmail.com> wrote:
> > I wish I had a tapestry component that would read a text file and
> randomly
> > output one of the rows.
> > Like a "quote rotator"... does anyone know if it exists out there or
> will I
> > have to write it myself?
> >
> > If I'd write it myself... how would I do - any suggestions?
> > I suppose I'd wan't to read the file (which is small) in a static
> variable
> > so I only need to do this once per class loader?
> > How do I specify the asset file and how will my component find it...hmmm
> >
> > Any help highly appreciated!
> >
> > Malin
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Text rotator component

Posted by Sam Gendler <sg...@ideasculptor.com>.
depends on what kind of infrastructure you want.  In the simplest
case, just hardcode a file path into a class, open it and read its
contents in a static block, and then just access from an Insert
component (<binding name="value"
value="ognl:myFileReaderObject.randomLine"/>)

One step up would be to place the filepath in a config file included
with your webapp. Either stick it in a hivemind config as a parameter
to a service object, do something similar with a spring
application-context, or even push it into your servlet from the
web.xml file.

If you absolutely must have a component and the component really must
be passed a data source at each render time, presumably because you
want to be able to choose from many sources, I would just have your
component receive a model object which adheres to some interface, then
provide an instance of that class to your page via hivemind (or
spring), and configure the filepath in the hivemind.spring config.

It still seems easier to me to have some kind of service object which
can provide a line of text at random, and then just insert the text
into the page via an Insert component.  The only reason to make it a
standalone component is if you need to wrap the text in some custom
html, and that is simple enough.

--sam


On 11/13/06, Malin Ljungh <ma...@gmail.com> wrote:
> I wish I had a tapestry component that would read a text file and randomly
> output one of the rows.
> Like a "quote rotator"... does anyone know if it exists out there or will I
> have to write it myself?
>
> If I'd write it myself... how would I do - any suggestions?
> I suppose I'd wan't to read the file (which is small) in a static variable
> so I only need to do this once per class loader?
> How do I specify the asset file and how will my component find it...hmmm
>
> Any help highly appreciated!
>
> Malin
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org