如何在具有定制外观和感觉的单个 Grails 应用程序中处理多个客户?

发布于 2024-08-13 23:46:08 字数 525 浏览 3 评论 0 原文

我的应用程序需要在运行时支持多个客户。它们都将使用相同的控制器、服务但具有不同的布局、CSS 和图像来显示相同​​的数据。

我的基本想法如下:

1)有一个过滤器来进行身份验证并在会话中设置配置值 2)我的控制器代码将调用以下内容: render(view:"/${session.userContext}/test/test")

因此,对于 customer1,我们将渲染:views/customer1/test/test.gsp

理想情况下,我希望在 /views 中拥有所有自定义视图和布局/customer1/ 目录,但站点网格在 /views/layouts 目录中查找布局,但我找不到解决此问题的方法。从这个意义上说,该解决方案有点笨拙,因为我没有达到我想要的隔离级别。

理想的情况是,如果我可以在运行时设置 grails 渲染方法的根,例如,而不是从视图开始,而是查看views/customer1,唉,我不知道如何做到这一点,但他似乎是最聪明的解决方案。

任何帮助将不胜感激。

干杯,

加夫

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:"/${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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年已逝 2024-08-20 23:46:08

我建议考虑创建 GrailsLayoutDecoratorMapper。由于您可以访问完整的 HttpServletRequest,因此您可以根据如何区分一个客户与另一个客户(域、会话变量等)来呈现不同的视图。如果您无法确定当前请求的正确视图/布局,您可以简单地委托给 GrailsLayoutDecoratorMapper 来保留默认行为。

要配置自定义DecoratorMapper,需要修改/web-app/WEB-INF/sitemesh.xml并替换默认的 使用您的自定义实现。

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.

绝不放开 2024-08-20 23:46:08

查看 多租户插件 - 看起来它可以帮助您完成其余的工作你的应用程序也是如此。

您必须处理指定 布局来自控制器,通过传入布局名称 -> 我不认为您能够让 Grails 隔离您的布局而不覆盖默认的布局装饰器映射 bean。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文