Comments (4)
Appears that thymeleaf has made some improvements to handle this.
from spring-mobile.
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.
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.
Created a long issue related to this on thymeleaf repo: thymeleaf/thymeleaf#300
from spring-mobile.
Related Issues (20)
- DeviceWebArgumentResolver implementation HOT 2
- Blackberry 10 user agent missing HOT 1
- Wrong device detection for a Nokia Lumia 620 HOT 3
- RedirectAttributes flashAttribute not working in mobile switch HOT 1
- AbstractSitePathUrlFactory doesn't handle empty paths correctly HOT 1
- Detection systems provide HOT 3
- New Structure For Device and Device Resolving HOT 5
- SiteSwitcher Disables the DeviceResolver
- Bot User-Agent conflicting with KNOWN_MOBILE_USER_AGENT_PREFIXES HOT 5
- Wrong device detected HOT 1
- SAMSUNG I9308 mobile , Device incorrect HOT 1
- Make LiteDevice a public class HOT 2
- Windows phones platform resolved as Android HOT 1
- Metadata for "spring.mobile" isn't generated anymore
- iOS13 iPad User Agent Issue HOT 1
- Status of the project? HOT 1
- About Google to phase out user-agent strings in Chrome
- spring-mobile-device also support spring-webflux?
- Is this a deprecated repo? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-mobile.