Quantcast

Rendering block from Java

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Rendering block from Java

Jaroslav Ciml
Hi,

Is rendering of a block possible directly from Java code?

I know that I can return a block from a rendering phase method:

Object beginRender()
{
    if (someCondition) {
        return someBlock; // of type org.apache.tapestry5.Block
    }
    ...
}

However, can I do something like

Object beginRender(MarkupWriter writer)
{
    writer.write("Leading text");
    if (someBlock != null)
    {
        writer.renderBlock(someBlock); // this method does not actually exist
    }
    writer.write("Trailing text");
}

Thanks.
Jarda

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rendering block from Java

nquirynen
Hey,

I'm not sure with blocks, but I do know that Lance (Tapestry committer)
made a library to render pages and components in code. Maybe this can
help you with your case?

https://github.com/uklance/tapestry-offline


Nathan


Op 06/01/2017 om 18:12 schreef Jaroslav Ciml:

> Hi,
>
> Is rendering of a block possible directly from Java code?
>
> I know that I can return a block from a rendering phase method:
>
> Object beginRender()
> {
>      if (someCondition) {
>          return someBlock; // of type org.apache.tapestry5.Block
>      }
>      ...
> }
>
> However, can I do something like
>
> Object beginRender(MarkupWriter writer)
> {
>      writer.write("Leading text");
>      if (someBlock != null)
>      {
>          writer.renderBlock(someBlock); // this method does not actually exist
>      }
>      writer.write("Trailing text");
> }
>
> Thanks.
> Jarda
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rendering block from Java

Lance Java
There's also the capture component
http://t5stitch-lazan.rhcloud.com/capturedemo

On 6 Jan 2017 5:17 p.m., "Nathan Quirynen" <[hidden email]>
wrote:

> Hey,
>
> I'm not sure with blocks, but I do know that Lance (Tapestry committer)
> made a library to render pages and components in code. Maybe this can help
> you with your case?
>
> https://github.com/uklance/tapestry-offline
>
>
> Nathan
>
>
> Op 06/01/2017 om 18:12 schreef Jaroslav Ciml:
>
>> Hi,
>>
>> Is rendering of a block possible directly from Java code?
>>
>> I know that I can return a block from a rendering phase method:
>>
>> Object beginRender()
>> {
>>      if (someCondition) {
>>          return someBlock; // of type org.apache.tapestry5.Block
>>      }
>>      ...
>> }
>>
>> However, can I do something like
>>
>> Object beginRender(MarkupWriter writer)
>> {
>>      writer.write("Leading text");
>>      if (someBlock != null)
>>      {
>>          writer.renderBlock(someBlock); // this method does not actually
>> exist
>>      }
>>      writer.write("Trailing text");
>> }
>>
>> Thanks.
>> Jarda
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rendering block from Java

Thiago H de Paula Figueiredo
In reply to this post by Jaroslav Ciml
On Fri, Jan 6, 2017 at 3:12 PM, Jaroslav Ciml <[hidden email]>
wrote:

> Hi,
>
> Is rendering of a block possible directly from Java code?
>

The way you describe in your example, I don't think so, and I would try to
avoid doing this kind of thing. Couldn't you break the leading text and
trailing text into separate components instead and then create another
component using them? That's what I'd do.


>
> I know that I can return a block from a rendering phase method:
>
> Object beginRender()
> {
>     if (someCondition) {
>         return someBlock; // of type org.apache.tapestry5.Block
>     }
>     ...
> }
>
> However, can I do something like
>
> Object beginRender(MarkupWriter writer)
> {
>     writer.write("Leading text");
>     if (someBlock != null)
>     {
>         writer.renderBlock(someBlock); // this method does not actually
> exist
>     }
>     writer.write("Trailing text");
> }
>
> Thanks.
> Jarda
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Thiago
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rendering block from Java

Thiago H de Paula Figueiredo
In reply to this post by nquirynen
Since 5.4, Tapestry has the PartialTemplateRenderer service, which renders
different objects and returns them as a String:
http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/PartialTemplateRenderer.html
.

Example:
https://github.com/apache/tapestry-5/blob/master/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PartialTemplateRendererDemo.java
https://github.com/apache/tapestry-5/blob/master/tapestry-core/src/test/app1/PartialTemplateRendererDemo.tml

On Fri, Jan 6, 2017 at 3:17 PM, Nathan Quirynen <[hidden email]
> wrote:

> Hey,
>
> I'm not sure with blocks, but I do know that Lance (Tapestry committer)
> made a library to render pages and components in code. Maybe this can help
> you with your case?
>
> https://github.com/uklance/tapestry-offline
>
>
> Nathan
>
>
> Op 06/01/2017 om 18:12 schreef Jaroslav Ciml:
>
> Hi,
>>
>> Is rendering of a block possible directly from Java code?
>>
>> I know that I can return a block from a rendering phase method:
>>
>> Object beginRender()
>> {
>>      if (someCondition) {
>>          return someBlock; // of type org.apache.tapestry5.Block
>>      }
>>      ...
>> }
>>
>> However, can I do something like
>>
>> Object beginRender(MarkupWriter writer)
>> {
>>      writer.write("Leading text");
>>      if (someBlock != null)
>>      {
>>          writer.renderBlock(someBlock); // this method does not actually
>> exist
>>      }
>>      writer.write("Trailing text");
>> }
>>
>> Thanks.
>> Jarda
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Thiago
Loading...