更改primefaces theme
PrimeFaces is using jQuery ThemeRoller CSS theme framework, and come with 30+ pre-designed themes that you can download and apply in seconds. In this tutorial, we will show you how to change a theme n PriceFaces.
There are two ways to change a theme :
- Using Maven to download and apply.
- Download manually and apply.
1. Maven Download
For Maven user, visit this PrimeFaces available theme, select a theme and remember the theme, defined in Maven and configure the web.xml
.
In this case, we will show you how to change a default theme (aristo) to glass-x theme.
File : pom.xml
//... <repositories> <repository> <id>prime-repo</id> <name>Prime Repo</name> <url>http://repository.primefaces.org</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.primefaces.themes</groupId> <artifactId>glass-x</artifactId> <version>1.0.6</version> </dependency> <dependencies>
Visit this PrimeFaces repository directly, check the theme folder to know which one is the latest.
File : web.xml
//... <context-param> <param-name>primefaces.THEME</param-name> <param-value>glass-x</param-value> </context-param>
Run it, the theme color will be changed, and looking inside the source code, it point to glass-x now.
<!-- html source code --> <link type="text/css" rel="stylesheet" href="/project/faces/javax.faces.resource/theme.css?ln=primefaces-glass-x" />
2. Download Manually
For non-Maven user, just visit the PrimeFaces’s repository and download the theme jar manually, and put it in your project classpath, and configure the web.xml
.
File : web.xml
//... <context-param> <param-name>primefaces.THEME</param-name> <param-value>glass-x</param-value> </context-param>
Change Theme Dynamic
A nice trip to use EL expression to apply a theme dynamically. See following code snippet :
File : web.xml
<context-param> <param-name>primefaces.THEME</param-name> <param-value>#{loggedInUser.preferences.theme}</param-value> </context-param>
P.S Reference – PrimeFaces user guide
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?