如何在 Primefaces 3 中通过 Java 代码设置主题?

发布于 2024-12-20 11:56:07 字数 163 浏览 0 评论 0原文

例如,我有主题 test。如何在 Primefaces 中使用 Java 代码设置此主题?我不想使用上下文参数 primefaces.THEME 并且我不想使用

I have for example theme test. How to set this theme using Java code in Primefaces ? I don't want to use context param primefaces.THEME and i don't want to use <p:themeSwitcher>.

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

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

发布评论

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

评论(2

我ぃ本無心為│何有愛 2024-12-27 11:56:07

另一种方法是:将样式表包含到页面模板中:



其中 #{themesBean.theme} 变量引用您的主题名称。

PS在PF5中测试

类似问题的相同答案 https://stackoverflow.com/a/24092773/2993327

One more way to do this: include stylesheet to your pages template:

<h:body>
<h:outputStylesheet library="primefaces-#{themesBean.theme}" name="theme.css" />
</h:body>

Where #{themesBean.theme} variable reffers to name of your theme.

P.S. tested in PF5

Same answer on similar question https://stackoverflow.com/a/24092773/2993327

来日方长 2024-12-27 11:56:07

这就是您需要做的(未经测试,但应该告诉您它应该如何工作)

  • 禁用标准主题支持(在 web.xml 中):

代码:

<context-param>
  <param-name>primefaces.THEME</param-name>
  <param-value>none</param-value>
</context-param>
  • 创建一个托管 bean(CDI 或 std JSF)来保存主题。

代码:

@Named @SessionScoped
public class LayoutBean
{
    ...
    private String theme = "test";
    ...
    public String getTheme()
    {
        return theme;
    }
    ...
}
  • 在所有页面的头部添加以下标签(模板)

代码:

 <link rel="stylesheet" href="#{request.contextPath}/themes/{layoutBean.theme}/skin.css" />

您可以在以下 URL 上找到此解决方案 如何设置 PrimeFaces 主题?

This is what you need to do (untested, but should give you an indication how it should work)

  • Disable standard theme support (in web.xml):

Code:

<context-param>
  <param-name>primefaces.THEME</param-name>
  <param-value>none</param-value>
</context-param>
  • Make a managed bean (CDI or std JSF) that holds the value for the theme.

Code:

@Named @SessionScoped
public class LayoutBean
{
    ...
    private String theme = "test";
    ...
    public String getTheme()
    {
        return theme;
    }
    ...
}
  • Add following tag in the head of all your pages (template)

Code:

 <link rel="stylesheet" href="#{request.contextPath}/themes/{layoutBean.theme}/skin.css" />

You can find this solution on the following URL how to set a PrimeFaces theme?

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