We did some digging around and learned that Faces 4.0 supports views written in Java, which is a much better solution for such questions than hacking templates. Thymeleaf is a template solution, where as Faces really is not.
A very nice example or programmatic Faces views is posted here: https://hantsy.github.io/jakartaee10-sandbox/faces/faces/ and about integration with Spring (we are not ready to throw Spring out of the project in favour of full jakarta namespace) here: https://habr.com/ru/articles/736474/