tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Wyraz <michael.wy...@evermind.de>
Subject Re: Tapestry 5.4, AngularJS and partial page content - how can I render a Block to raw HTML?
Date Thu, 07 Nov 2013 18:56:02 GMT
Thiago,

you're right, actually my solution does not use zones but partial 
rendererd blocks. I thought a bit about it and asked myself if it would 
not be much better to create a tapestry-bound routing for angular that 
really uses zones/blocks for navigation and templating.

At the moment I stay with my "partial render" approach because I need to 
stay in time with my proof-of-concept and there are still lots of 
problems to solve. If I end in a good solution, we are going to do 
bigger projects with that technologie and I can spend more time in 
making it better ;-)

For rendering a block to string I found 
https://issues.apache.org/jira/browse/TAP5-938 and tons of "hacks" so 
achieve this. I would like to see some service in tapestry to do such 
because otherwise it is only possible with really good knowledge of 
tapestry's internals. I'll check if the hacks still works with 5.4 and 
try to provide code for such a service.

I was about adding the "root node is not html" bug to jira but you 
already added it: https://issues.apache.org/jira/browse/TAP5-2200. I 
just put my comment on it and voted.

Regards,
Michael.




> On Thu, 07 Nov 2013 14:52:31 -0200, Michael Wyraz 
> <michael.wyraz@evermind.de> wrote:
>
>> No I did not. Thougt this was "by intend" - tapestry complains as soon
>> as the page root is not "html":
>>
>>     *The root element of the rendered document was <div>, not <html>.
A
>>     root element of <html> is needed when linking JavaScript and
>>     stylesheet resources.**
>
> Not actually. It complains after rendering when DocumentLinker tries 
> to add CSS and JavaScript to the page. I think we can add something 
> that tells DocumentLinker to not add stuff to the rendered markup in 
> that request.
>
>> Also tapestry would always inject it's stuff to the page. It might be
>> hard to change this.
>
> It's actually easy, even without changing the sources (but you 
> actually need to take a look at TapestryModule sources first), but I 
> want Tapestry to provide an easy way to do that.
>
>>>> 3. Tweak angularjs to use some zone update mechanism to load the
>>>> templates.
>>>> I have no idea if/how this is possible. If someone already did such,
>>>> please let me know.
>>> Hmm, that would probably be more complex than worth in the end.
>>>
>> Not really. I started to investigate in it:
>
> What you describe below is correct and clever, but it doesn't use 
> zones, so I told it would be hard to do, but we ended up talking about 
> different stuff. :P What you're doing is basically returning a Block 
> from an AJAX request.
>
>> In my page html I have:
>>      <script type="text/javascript">
>>          var templateBaseUri="${templateBaseUri}";
>>      </script>
>>
>> This returns an eventlink like "/mypage:gettemplate/"
>>
>> In my angularjs-router I use this template URI in the following way:
>>              .when('/', {
>>                  templateUrl: templateBaseUri+"startseite",
>>
>> This mages angularjs read all the templates via tapestry event
>> "gettemplate". The code there is:
>>
>>          public Object onGetTemplate(String templateName)
>>          {
>>              try
>>              {
>>                  Block block=resources.getBlock(templateName);
>>                  System.err.println("Block: "+block);
>>                  return block; // TODO render block as html fragment
>>              }
>>              catch (BlockNotFoundException ex)
>>              {
>>                  System.err.println("Template not found: 
>> "+templateName);
>>                  return new
>>     TextStreamResponse("text/html","<div>Template not found:
>>     "+templateName+"</div>");
>>              }
>>          }
>>
>> Not in my tml I change
>> <script type="text/ng-template" id="startseite">
>> to
>> <t:block t:id="startseite">
>>
>> That's all. The only thing left ist to render the block to HTML. If
>> anyone know how it is done, please let me know.
>
> There are solutions on the mailing lists and tapestry-offline.
>
> Or, better yet, use different pages for different views. Please file 
> the JIRA
>


-- 

Mit freundlichen Grüßen / Regards

Michael Wyraz

evermind GmbH
Schorlemmerstraße 1
04155 Leipzig

Tel.:       +49 (0)341-25 39 66 - 0
Fax:        +49 (0)341-25 39 66 - 1
Funk:       +49 (0)177-73 00 00 3
E-Mail:     michael.wyraz@evermind.de

HRB: 21586
Amtsgericht Leipzig

Geschäftsführer:
Christoph Klemm
Thomas Grünert
Michael Wyraz


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


Mime
View raw message