How to change Portlet Preferences programmatically

If you are doing big liferay projects for huge firms you will know the problem, that you have to configure a lot of portlets. A once you did all the configuration, you have to do it again and again because links change, colors change, sizes of portlets change and so on. This post is a suggestion what you could do to get rid of most of this work.
Liferay stores the portlet preferences in an own table called "portletpreferences". This table is also accessible by a LocalServiceUtil and (of course) Dynamic Queries.

So - what you have to do is : Write a portlet that accesses this table and changes strings. Here is an example how these preferences may look. Imagine a portlet that is storing the information "test", "width", "height", "someValue" and "booleanValue":


So, just iterate over all entries in the PortletPreferences table, check the portletId and change the preferenes column. This allows you to change a lot of portlet preferences with a simple click.

If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.