How Handle multiple customers in a single grails application with customised look and feel?
My app needs to support multiple customers at run time. They will all be displaying the same data, using the same controllers, services but with different layouts, css and images.
My basic idea is as follows:
1) Have a filter to authenticate and set a config value in the session 2) My controller code will call something along these lines: render(view开发者_StackOverflow中文版:"/${session.userContext}/test/test")
So for customer1 we will render: views/customer1/test/test.gsp
Ideally I would like to have the all custom views and layouts in the /views/customer1/ directory but site mesh looks for layouts in the /views/layouts directory and I can't find a way around this. In this sense the solution is a wee bit clunky as I don't get the level of isolation I want.
What would be ideal is if I could set the root of the grails render method at runtime e.g. instead of starting at views, look in views/customer1 alas I have no idea how to do this but his seems like the smartest solution.
Any help would be massivly appreciated.
Cheers,
Gav
I would recommend to look into creating a subclass of GrailsLayoutDecoratorMapper. Since you have access to the full HttpServletRequest, you can render a different view depending on how you differentiate one customer from another (domain, session variable, etc.). If you can't determine a proper view/layout for the current request, you can simply delegate to GrailsLayoutDecoratorMapper to keep the default behavior.
To configure a custom DecoratorMapper, you need to modify /web-app/WEB-INF/sitemesh.xml and replace the default <mapper class="org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper" />
with your custom implementaion.
Checkout the Multi-Tenant plugin - It looks like it can help you through the rest of your app as well.
You'll have to handle specifying the layouts from the controller, by passing in the layout name -> <meta name="layout" content="$layoutName">
I don't think You'd be able to get Grails to isolate your layouts without overriding the default Layout Decorator Mappings bean.
精彩评论