Partial AJAX Rendering

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Partial AJAX Rendering

ncanatta
Hello!

I am kind of new to thymeleaf, started working with it like 3 month ago, i just want to congratulate the creators and the community for the great JOB!! :)

Well, i have an idea about partial rendering when working with AJAX; I want to create a dialect that provides a way to facilitate this particular task.

For example:

I have a custom element that calls a method from the server and do a partial render of a table, based on the response received from the server:

-------------
<custom:ajax id="Element" url="app/ajaxtask" update="table"/>

                                                                                                                                                                                                                                                                                                                                        
Name
-------------

Today, i accomplish this by using fragments and the jQuery load function. I wonder if there is a way to reprocess the particular element i want to update (in the example the table element) in the DOM tree, so i can update the element by replacing its html content, with a new html code generated on the server.

Any thoughts will be welcome.

Thanks in advance!.
Nelson.



               
Reply | Threaded
Open this post in threaded view
|

Re: Partial AJAX Rendering

Zemi
Administrator
Hello,

jQuery load function is really what better fits here.

You could use a processor, as you have suggested, to generate the Javascript code.



Reply | Threaded
Open this post in threaded view
|

Re: Partial AJAX Rendering

danielfernandez
Administrator
In reply to this post by ncanatta

The TemplateEngine object can be instructed to process only partial templates by specifying an IFragmentSpec object as a parameter to its "process()" method.

See the IFragmentSpec interface and its out-of-the-box implementations here: https://github.com/thymeleaf/thymeleaf/tree/thymeleaf-2.0.15/src/main/java/org/thymeleaf/fragment

If you are using Spring, this IFragmentSpec can be specified at the specific ThymeleafView object being used for rendering: https://github.com/thymeleaf/thymeleaf-spring3/blob/thymeleaf-spring3-2.0.15/src/main/java/org/thymeleaf/spring3/view/ThymeleafView.java#L134

There is also support for "Spring JavaScript" (which is a part of Spring WebFlow) using several AJAX-enabled subclasses of Thymeleaf view, as you can see here: https://github.com/thymeleaf/thymeleaf-spring3/blob/thymeleaf-spring3-2.0.15/src/main/java/org/thymeleaf/spring3/view

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Partial AJAX Rendering

ncanatta
Thank you so much, Zemi and Daniel for the replies!

I think the IFragmentSpec interface is what I looking for, so I'll look into it in more detail. When I get some results, I'll share it.

Thank you for the starting point.

Nelson.