|
Total newb to extending grails functionality but what I'd like to do is to render alternate views based on some internal criteria?
In other words, if the standard view is say list.gsp, but we inherently know the request is from a mobile device, the controller would automatically delegate to list-mobile.gsp (if it exists) instead. This would be by convention and would not required logic in the controller. I would basically like to abstract the entire concept behind Spring Mobile Plugin for Grails. Is this possible via writing a plugin or would you have to fork the Grails source? |
|
you can use grails filters to check the request, if it is mobile, just add an request attr.
after the controller logic, the filter can check the parameter and change the view that will be rendered based on that.
I think would be transparent to the controller. []s, 2012/7/27 robotwasp <[hidden email]> Total newb to extending grails functionality but what I'd like to do is to |
|
In reply to this post by robotwasp
On 27 Jul 2012, at 11:44, robotwasp <[hidden email]> wrote: > Total newb to extending grails functionality but what I'd like to do is to > render alternate views based on some internal criteria? > > In other words, if the standard view is say list.gsp, but we inherently > know the request is from a mobile device, the controller would automatically > delegate to list-mobile.gsp (if it exists) instead. This would be by > convention and would not required logic in the controller. I would > basically like to abstract the entire concept behind Spring Mobile Plugin > for Grails. > > Is this possible via writing a plugin or would you have to fork the Grails > source? > Hi, I don't think it is possible because of all the code in grails and plugins that resolves GSPs and GSP templates (used in g:render) However... if memory serves correctly there is a little-used feature that loads GSPs based on content-negotiation and/or locales. I've never used it but see: http://grails.org/doc/latest/ref/Controllers/withFormat.html Basically using withFormat it can resolve GSPs to names like index.html.gsp when the content type is html. So you could argue that you can already do this out of the box using some custom content type mappings / a plugin with a filter to set the content type to e.g. "mobilehtml" when it detects a mobile user agent. Marc ~ ~ ~ Marc Palmer Freelancer (Grails/Groovy/Java/UX) I offer commercial support for Grails plugins from as low as $50/mo. For details see: http://grailsrocks.com Blog: http://www.anyware.co.uk | Resumé: http://www.anyware.co.uk/marc Contributor @ http://grails.org | Founder @ http://noticelocal.com Developer @ http://weceem.org | Member @ http://spottymushroom.com Twitter: http://twitter.com/wangjammer5 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by lucastex
Thanks Lucas!!! This sounds like a decent approach : a simple filter can interpret the media type and change the view using the after interceptor. On top of that it will work nicely as a plug-in. I'm going to experiment with this approach - will let you know how I get on. Thanks again for the advice.
RobotWasp |
|
In reply to this post by Marc Palmer Local
Thanks Marc,
This might be useful approach if the filters thing doesn't work out. Appreciate the advice. RW. |
| Powered by Nabble | Edit this page |
