You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Danny Mandel <dm...@tolweb.org> on 2004/10/25 19:54:10 UTC
converting component output to javascript
Hello fellow tapestraniacs. I am looking to somehow take the output
from one of my components and convert it into a javscript variable that
can be referred to from elsewhere on a page for mouseover events.
Right now I have a component that will generate a table with a listing
of all metadata associated with a given img and I want to be able to use
a similar component to generate a javascript variable holding the html
for the table.
Ideally I'd use a script specification for this, but I don't know how
(or if it's possible) to render other components inside a .script file.
Has anyone come across this problem before and found a nifty solution?
Thanks.
Sincerely,
Danny Mandel
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: converting component output to javascript
Posted by Markus Wiederkehr <ma...@gmail.com>.
I think it might be possible to render a component into a String and
pass that string to the script. I haven't tried it myself, but here is
what I would do:
Create a HTMLWriter that writes to a StringWriter:
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
IMarkupWriter writer = new HTMLWriter(pw);
Render your component to that IMarkupWriter:
IComponent component = getMyComponent();
IRequestCycle cycle = getRequestCycle();
component.render(writer, cycle);
Pass the result to your script:
writer.flush();
String html = sw.toString();
writer.close();
Map symbols = new HashMap();
symbols.put("html", html);
getScript().execute(cycle, body, symbols);
hth
Markus
On Mon, 25 Oct 2004 10:54:10 -0700, Danny Mandel <dm...@tolweb.org> wrote:
> Hello fellow tapestraniacs. I am looking to somehow take the output
> from one of my components and convert it into a javscript variable that
> can be referred to from elsewhere on a page for mouseover events.
>
> Right now I have a component that will generate a table with a listing
> of all metadata associated with a given img and I want to be able to use
> a similar component to generate a javascript variable holding the html
> for the table.
>
> Ideally I'd use a script specification for this, but I don't know how
> (or if it's possible) to render other components inside a .script file.
> Has anyone come across this problem before and found a nifty solution?
>
> Thanks.
>
> Sincerely,
> Danny Mandel
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org