Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Dinesh Balaji
How to apply theme for user's private pages
January 11, 2011 9:59 AM
Answer

Dinesh Balaji

Rank: Junior Member

Posts: 52

Join Date: October 6, 2010

Recent Posts

Hi All !

I want to apply theme for user's private pages in a programmatic manner. For this, I have created a hook and i hard-coded the users and i set the condition to apply theme for particular user's private pages. I didn't get any errors and the problem was the theme is not applied for particular user(Default is applied ). Here is my code :

package com.sample.hook;

import com.liferay.portal.kernel.events.Action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.struts.LastPath;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.liferay.portal.service.ThemeLocalServiceUtil;
import com.liferay.portal.model.Theme;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;


public class LoginAction extends Action
{
public void run(HttpServletRequest req, HttpServletResponse res) throws ActionException
{
System.out.println(":entry 1");

try {

long userId = PortalUtil.getUserId(req);
User user = UserLocalServiceUtil.getUser(userId);

Theme theme = null;


if(user.getFullName().equals("test1"))
{

LayoutSetLocalServiceUtil.updateLookAndFeel(1, "theme-1", " ", " ", false);
}

else if(user.getFullName().equals("test2"))
{
LayoutSetLocalServiceUtil.updateLookAndFeel(1, "theme-2", " ", " ", false);

}
}
catch (PortalException ex)
{
System.out.println("Portal Error");

}
catch (Exception ex)
{
System.out.println("General Error");

}
}
}


Can anyone suggest me how to achieve this ?

Thanks in advance.

Regards,
Dinesh
Jelmer Kuperus
RE: How to apply theme for user's private pages
January 11, 2011 1:40 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

1LayoutSetLocalServiceUtil.updateLookAndFeel(user.getGroup().getGroupId(), themeId, colorSchemeId, "", false);


where themeId is the unique theme id. Suppose you built your own theme called my-theme and deployed it as a war then your themeId would be my_WAR_mytheme

for colorSchemeId you would typically use "01"
Tanaji Londhe
RE: How to apply theme for user's private pages
July 17, 2013 1:17 AM
Answer

Tanaji Londhe

Rank: Regular Member

Posts: 196

Join Date: April 25, 2012

Recent Posts

Hi Jelmer,
while applying theme for pages, how do you differentiate that page are public or private.
Beacuse when i update look and feel, it apply only for public pages.
Sharad Sinha
RE: How to apply theme for user's private pages
July 17, 2013 1:36 AM
Answer

Sharad Sinha

Rank: Junior Member

Posts: 39

Join Date: March 7, 2013

Recent Posts

Hi Tanaji,

You can differentiate user's private and public page by using

layout.isPrivateLayout()

Try to update theme for user's private page with this code:



LayoutLocalServiceUtil.updateLookAndFeel(groupId, // GroupId not Scope groupId
true, // public layout or private layout ( True if you want to update theme for private page)
LayoutId, // Layout Id
ThemeId, // ThemeId
ColorSchemeId, // color SchemeId
css, //CSS
Wap // true or false for Wap theme
);





I hope this will help you.


Thanks
Sharad Sinha