[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Mobile + Thymeleaf with fallback to desktop view #63

Open
dchartfield opened this issue Jul 18, 2014 · 0 comments
Open

Spring Mobile + Thymeleaf with fallback to desktop view #63

dchartfield opened this issue Jul 18, 2014 · 0 comments

Comments

@dchartfield
Copy link

Hello, I am using Spring Mobile with Thymeleaf and it is working well. One thing I would like to be able to do is to set the viewResolver to fallback to the the desktop template if a mobile template is not found.

Spring Mobile's LiteDeviceDelegatingViewResolver ( org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver ) has the option to setEnableFallback( true ), which means before it calls to it's delegating viewResolver ( in my case the AjaxThymeleafViewResolver) with the resolveViewName method it adds a mobile prefix to the template name ( say "mobile/" ), and if resolveViewName returns null, it will try again without the mobile prefix. The Javadoc reads:

Enables support for fallback resolution, meaning if the adjusted view name cannot be resolved, and attempt will be made to resolve the original view name. This may be helpful in situations where not all views within a web site have device specific implementations.

Note: fallback resolution will only work when delegating to a view resolver which returns null from resolveViewName(String, Locale) if it cannot resolve a view. For example, InternalResourceViewResolver never returns null, so fallback resolution will not be available.

My understanding of Thymeleaf's viewResolver is that it does not check if the template actually exists during the resolveViewName step after reading this: http://forum.thymeleaf.org/Chaining-view-resolvers-td3295026.html

The reason seems to be that it allows for the flexibility where templates are located, etc.

The solution I was thinking of to allow for this functionality was that suggested in the last article (at the bottom of this one: http://forum.thymeleaf.org/Chaining-view-resolvers-td3295026.html ) of overriding the canHandle method of a the ThymeleafViewResolver to check if the template actually exists. Has any better solution been used or suggested? Are there any unintended side effects this solution could cause?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants