Skip to content
Advertisement

How to change Thymeleaf fragments dynamically depending on the href link

I want to build a page with Thymeleaf fragments, which are rendered dynamically depending on the followed link.
And I have an issue with resolving fragments names in runtime through the Spring controller.

Here is the minimal reproductive example to show what I mean.


I have list.html page with two links List 1 and List 2 with pic and code as below:

Links

JavaScript

The related Spring controller looks as:

JavaScript

The problem that fragmentName is not being resolved at runtime and it throws TemplateInputException exception:

JavaScript

At the same time static block works correctly as shown in list.html page code.

Please don’t suggest me Spring MVC 3.2 Thymeleaf Ajax Fragments, I don’t want to use AJAX, I found the current solution of returning the fragment name using controller very clear and simple for my case.

Probably I can use Fragment Expressions, but I am not sure how exactly.
Any suggestions are appreciated.

Advertisement

Answer

I would express the syntax like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement