Each user needs to change theme in session

Forum rules
Please note that response time for technical support is within 3-5 business days.
Post Reply
lbordinhon
Posts: 10
Joined: 03 Feb 2023, 14:41

22 Jun 2023, 21:02

Hello Guys!
I'm using primefaces 12 and springboot 2.7

I made a bean (guestPreferences) to controller de themes to each user using scope session.

It's working when i set in menu theme config:
Image

but i'm setting primefaces.THEME parameter in onStartup's springboot. So i update page and the theme of primefaces.THEME setted returns.
I searched and the context-param in web.xml don't works because springboot don't reads web.xml

Code: Select all

	<context-param>
		<param-name>primefaces.THEME</param-name>
		<param-value>#{guestPreferences.theme}</param-value>
	</context-param>
In onStartup the context is initialized and after don't can change the prameter.

Exists some primefaces configuration to set theme after context in initialized?

Thanks!

olgubasak
Posts: 98
Joined: 05 Jan 2023, 11:05

27 Jun 2023, 16:01

Hi,
Actually, I am not familiar with the usage of PrimeFaces and Spring Boot, but when I searched for a solution suggestion, you can try the following result:

1-Create a GuestPreferences bean to hold the theme preference for each user. Make sure it has a theme property that can be updated dynamically.

2-In your application.properties or application.yml file, configure the primefaces.THEME parameter to be dynamically linked with the guestPreferences.theme value.

-For application.properties, add the following line:

Code: Select all

primefaces.THEME=${guestPreferences.theme}
-For application.yml, add the following configuration:

Code: Select all

primefaces:
  THEME: ${guestPreferences.theme}
By using ${guestPreferences.theme}, the primefaces.THEME parameter will be associated with the value of guestPreferences.theme and updated accordingly.

3-Ensure that your GuestPreferences bean is properly managed by Spring and available for injection.

4-When your Spring Boot application starts or refreshes, Spring Boot will read the primefaces.THEME parameter from the configuration file and link it with the guestPreferences.theme property.

This allows you to update the theme property of the GuestPreferences bean dynamically, and PrimeFaces will automatically use the updated theme value.

To summarize, the correct approach is to configure the primefaces.THEME parameter in your application.properties or application.yml file and link it with the guestPreferences.theme value. This leverages Spring Boot's configuration mechanism to update the PrimeFaces theme dynamically.

I hope it helps.
Best Regards

Post Reply

Return to “Barcelona - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests