Giter Club home page Giter Club logo

Comments (4)

royclarkson avatar royclarkson commented on June 16, 2024 1

Appears that thymeleaf has made some improvements to handle this.

from spring-mobile.

royclarkson avatar royclarkson commented on June 16, 2024

That's an interesting scenario. I have not tested this, and I may not understand correctly, but I wonder if you can configure two LiteDeviceDelegatingViewResolver wrappers for each Thymeleaf view resolver. Then you can set the viewNames property to filter to the html or xhtml view folders.

from spring-mobile.

dgomesbr avatar dgomesbr commented on June 16, 2024

Hey @royclarkson , thanks for your time, again, the thymeleaf structure works like this:

templateEngine has templateResolvers which fills a templateRepository, but then again they all works under a premise that you only use one/a unique viewResolver strategy.

Meanwhile in the land of production code :(

You can't have two SpringTemplateEngines instantiated at same time (which I think is correct), but templateResolvers are added to templateEngines, so taking this code as a bean instantiation:

    @Bean
    public SpringTemplateEngine templateEngine()
    {
        final StandardCacheManager manager = new StandardCacheManager();
        manager.setTemplateCacheMaxSize(80);
        manager.setExpressionCacheUseSoftReferences(true);

        // the template engine relies on TemplateResolvers
        final SpringTemplateEngine engine = new SpringTemplateEngine();
        templateResolvers.add(templateResolver());
        templateResolvers.add(staticTemplateResolver());

        engine.setTemplateResolvers(templateResolvers);
        engine.addDialect(new DataAttributeDialect());

        ...

         return engine
    }

This templateEngine is able to retrieve templates but does the job only if you have only one view of each kind, let's take a look on this other piece of code for a moment:

    private ServletContextTemplateResolver createTemplateResolver(final String prefix, final String sufix, final String templateMode)
    {
        final String profile = env.getProperty("profile", "DEV");

        final ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
        resolver.setPrefix(prefix);
        resolver.setSuffix(sufix);
        resolver.setTemplateMode(templateMode);
        resolver.setCharacterEncoding("UTF-8");
        resolver.setOrder(1);
        resolver.setCacheable(env.getProperty(profile + ".template.cache", Boolean.class, false));
        resolver.setCacheTTLMs(FIVE_HOUR_CACHE);
        return resolver;
    }

    @Bean
    public ServletContextTemplateResolver HighEndTemplateResolver()
    {
        return createTemplateResolver("/WEB-INF/pages/html/", ".html", "HTML5");
    }

    @Bean
    public ServletContextTemplateResolver LowEndTemplateResolver()
    {
        return createTemplateResolver("/WEB-INF/pages/xhtml/", ".xhtml", "XHTML");
    }

The problem lies in:
- Users access /home.xhtml
- Projects tries to use liteDeviceViewResolver/ContentNegotiation to decide when to serve the html or the xhtml version of the site
- resolveViewName of ContentNegotiation realizes that has two views named home (home.html, home.xhml)
- getBestView will return the correct version based on extesion/acceptHeader which is xhtml/home.xhtml
- even tho the client asking for xhtml, templateResolver of thymeleaf will match the first HOME it encounters, if Xhtml is 1st then it will give the correct version, if not the html5 will be served.

That's my current situation :/

I'm looking for some guidance for the Spring part while doing the same on the thymeleaf forums.

from spring-mobile.

dgomesbr avatar dgomesbr commented on June 16, 2024

Created a long issue related to this on thymeleaf repo: thymeleaf/thymeleaf#300

from spring-mobile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.