You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Charles Roth <ro...@thedance.net> on 2012/03/09 01:16:14 UTC

Re: Programmatical page/component rendering

Could someone expand (expound?) more on rendering a Tapestry 5 component
*inside* a java class?

For example, I have an application I'm rewriting (from an
ancient-god-help-me-C-program) in Tapestry.  It's a venerable forum tool
that lets users put "macros" in their posts.  Each macro is rather like a
Tapestry component.

So as I'm rendering the page in the normal Tapestry way, I also want to
parse the users's posts, and be able to evaluate (render) the macros
(components) in the posts, and then spit the output, probably via
outputraw(?), to the Tapestry page.

So for example, a user's post might have something like:
   "Hey, I'm living now at %googleMap(latitude,longitude), and it's really
%blink(cool)!"

I want to be able to parse out the %googleMap and evaluate it (render it) as
a component (that I will write), then parse out the %blink and evaluate it
as another component (say, ye olde HTML blink tag)... accumulate all of the
user's text plus the rendered components, and THEN spit out all of the text.

Trying to do this with a (large!) collection of blocks would be tedious, and
maybe even impossible.  But this thread suggests that there are other ways
to do it, programmatically inside the Java class for a page.

Any hints or pointers are most welcome.  Thanks in advance!

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Programmatical-page-component-rendering-tp5159795p5549303.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Programmatical page/component rendering

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
I guess you could solve the problem another way: process the macros before  
the content is sent for Tapestry to render. Once I had a similar problem  
to solve (macros) and that's how I solved it. Tapestry templates were  
never meant to be used by users, just by developers. So, if you need  
templates and macros, you use a template engine (FreeMarker is quite good)  
and pass its output to OutputRaw. If Tapestry components are needed, I  
used to following trick: I've put them in pages inside a block. To render  
them, I use ComponentSource.getPage() to get the page, then  
getComponentResources().findBlock() to get the block, add information  
needed by the block through the Environment, then used Delegate to render  
the block. Works quite well. :)

Another option is to use Tapestry DOM rewriting in @AfterRender.

On Thu, 08 Mar 2012 21:16:14 -0300, Charles Roth <ro...@thedance.net> wrote:

> Could someone expand (expound?) more on rendering a Tapestry 5 component
> *inside* a java class?
>
> For example, I have an application I'm rewriting (from an
> ancient-god-help-me-C-program) in Tapestry.  It's a venerable forum tool
> that lets users put "macros" in their posts.  Each macro is rather like a
> Tapestry component.
>
> So as I'm rendering the page in the normal Tapestry way, I also want to
> parse the users's posts, and be able to evaluate (render) the macros
> (components) in the posts, and then spit the output, probably via
> outputraw(?), to the Tapestry page.
>
> So for example, a user's post might have something like:
>    "Hey, I'm living now at %googleMap(latitude,longitude), and it's  
> really
> %blink(cool)!"
>
> I want to be able to parse out the %googleMap and evaluate it (render  
> it) as
> a component (that I will write), then parse out the %blink and evaluate  
> it
> as another component (say, ye olde HTML blink tag)... accumulate all of  
> the
> user's text plus the rendered components, and THEN spit out all of the  
> text.
>
> Trying to do this with a (large!) collection of blocks would be tedious,  
> and
> maybe even impossible.  But this thread suggests that there are other  
> ways
> to do it, programmatically inside the Java class for a page.
>
> Any hints or pointers are most welcome.  Thanks in advance!
>
> --
> View this message in context:  
> http://tapestry.1045711.n5.nabble.com/Programmatical-page-component-rendering-tp5159795p5549303.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
http://www.arsmachina.com.br

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