Troubles Upgrading to Thymeleaf3

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

Troubles Upgrading to Thymeleaf3

paranoiabla
Hello,

I'm updating my attribute processor to thymeleaf3 and I need some help. Can you tell me what happened to the org.thymeleaf.dom package and the TemplateRepository? I need to migrate this code:

        final Map<String, Object> pagefragments = arguments.getLocalVariables();
        final List<Node> nodes = new TemplateRepository(configuration).getFragment(arguments, builder.toString());

        // Replace the children of this element with those of the replace page
        // fragments, scoping any fragment parts to the immediate children
        element.clearChildren();
        if (nodes != null) {
            for (final Node node : nodes) {
                node.setAllNodeLocalVariables(pagefragments);
                element.addChild(node);
            }
        }
        element.getParent().extractChild(element);


Also thymeleaf-spring4 used to have this class SpringWebContext, which would give you access to both ApplicationContext and HttpServletRequest. How can I get access to the applicationContext in my attribute processor now?

Thank you.

Reply | Threaded
Open this post in threaded view
|

Re: Troubles Upgrading to Thymeleaf3

Emanuel
Administrator
In short, the entire DOM package is gone.  Thymeleaf 3.0 moved to an event-based architecture, which is great for performance, but does make migrating dialects that depended on a DOM very difficult (I'm having great difficulty updating the layout dialect because of it...)

You'll need to scan the links of the BETA posts to see how to write dialects now that we don't have a DOM to play with: http://forum.thymeleaf.org/Thymeleaf-3-0-0-BETA03-just-published-td4029622.html  I've found the most useful ones the new dialect APIs as those describe this "structureHandler" object that you can use to manipulate the template.

I'm not sure about the Spring web context though.  Hopefully someone will have an answer, or the links in the beta post above will have some information.
Reply | Threaded
Open this post in threaded view
|

Re: Troubles Upgrading to Thymeleaf3

danielfernandez
Administrator
In reply to this post by paranoiabla
Hello,

As Emanuel says, Thymeleaf 3 is a complete rewrite of the engine, and that means new architecture and new APIs. The new engine is not DOM-based anymore.

Besides having a look at the links in the announcement page Emanuel mentions, I suggest you have a look at https://github.com/thymeleaf/thymeleafexamples-extrathyme, the example application for the "Extending Thymeleaf" manual (which is in the process of being updated to 3.0). The application is already updated and its processors of different kinds will give you a clue on how to adapt your specific needs: https://github.com/thymeleaf/thymeleafexamples-extrathyme/tree/3.0-master/src/main/java/thymeleafexamples/extrathyme/dialects/score

Also... isn't what you are doing mostly equivalent to a th:replace? Note the local variables are no longer managed by DOM nodes (or their replacements, engine events). The context object takes complete responsibility for that, and 99% of the time that should be transparent to dialect implementors...

As for the ApplicationContext, there is a SpringContextUtils class that will help you with obtaining the ApplicationContext. Note however that it is available in 3.0.0-SNAPSHOT only (not in 3.0.0.BETA03).

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

Re: Troubles Upgrading to Thymeleaf3

danielfernandez
Administrator
In reply to this post by paranoiabla
Please note we have just updated the "Extending Thymeleaf" tutorial (and companion example application) to cover Thymeleaf 3.0.

You can find it here: http://www.thymeleaf.org/documentation.html