Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sandeep Nair
Dynamic Theme for organization in Liferay 5.1.2[Resolved]
November 30, 2009 4:56 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Hi,

I am using Liferay 5.1.2

My problem statement is like we have multiple themes based on organization. I want when user logs in he should be able to see the theme based on his organization. Is there a way to do this tweaking some code?

Regards,
Sandeep
Sandeep Nair
RE: Dynamic Theme for organization in Liferay 5.1.2
November 27, 2009 4:50 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Please any help in this will be greatly appreciated. I just need to know where is the entry point where i can set the theme for a user so that it persists in next screens after he logs in.

Regards,
Sandeep
Tor Iver Wilhelmsen
RE: Dynamic Theme for organization in Liferay 5.1.2
November 27, 2009 5:52 AM
Answer

Tor Iver Wilhelmsen

Rank: Junior Member

Posts: 60

Join Date: December 3, 2008

Recent Posts

We solved this by writing a request action that checked that the URL was /c/portal and then checked the user's organisation, setting the request properties for theme and color scheme appropriately. The class needs to be put onto the portal classpath and added to the list of actions in portal-ext.properties, or added a a hook plugin if they actually ever got that to work properly.
Sandeep Nair
RE: Dynamic Theme for organization in Liferay 5.1.2
November 29, 2009 9:17 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Thanks Tor,

Can you please share the snippet of code and step by step instructions.?

Thanks & Regards,
Sandeep
Kowbathullah Gnaniyar
RE: Dynamic Theme for organization in Liferay 5.1.2
November 29, 2009 11:40 PM
Answer

Kowbathullah Gnaniyar

Rank: Liferay Master

Posts: 603

Join Date: December 19, 2007

Recent Posts

Hi Sandeep,

How many organization you have? if it is countable organization, you can select different theme for different organization manually?

or

After Login, you have to set the Theme Id in layout table programmatically like this :

public static Layout updateLookAndFeel(java.lang.String layoutId,
java.lang.String ownerId,
java.lang.String themeId,
java.lang.String colorSchemeId)


- Gnaniyar Zubair
Sandeep Nair
RE: Dynamic Theme for organization in Liferay 5.1.2
November 30, 2009 1:16 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Thanks mate,

That made my day. I would use it in a newly created login post action.

Thanks again,
Sandeep
Dinesh Balaji
RE: Dynamic Theme for organization in Liferay 5.1.2
January 5, 2011 2:26 AM
Answer

Dinesh Balaji

Rank: Junior Member

Posts: 52

Join Date: October 6, 2010

Recent Posts

Hi,
Currently I am using Liferay 6.

We also got a similar situation. We have 10 organisation , and we want different theme to be applied to different useres based on the organisaton they are in . I dont want this to do manually. Can we achieve this in portal-ext.properties or VM files.

Regards,
Dinesh Balaji V
Dhivya Das
RE: Dynamic Theme for organization in Liferay 5.1.2
January 9, 2011 8:07 AM
Answer

Dhivya Das

Rank: New Member

Posts: 9

Join Date: December 29, 2010

Recent Posts

Hi Sandeep,

I am facing similar problem. Can you please explain me in detail how to achieve this ? It will be very helpful for me. Thanks in advance.

Regards
Dhivya
Sandeep Nair
RE: Dynamic Theme for organization in Liferay 5.1.2
January 10, 2011 1:13 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

As you see i did it in 5.1.2 when i could modify the source coz then it was MIT license. Basically the logic is when user logs in find his organization. From the organization find group and all the layouts of the group. And using loop update the layout look and feel using the above method.

You may want to create a hook may be login post action hook to write the above logic
Dinesh Balaji
RE: Dynamic Theme for organization in Liferay 5.1.2
January 11, 2011 9:47 AM
Answer

Dinesh Balaji

Rank: Junior Member

Posts: 52

Join Date: October 6, 2010

Recent Posts

Hi Sandeep!

I followed your suggestion and created a hook. I was trying to set the theme for user's private page. I have two users which is hard-coded. The problem i was getting is the theme is not applied, it is directly taking the default theme. 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");

}
}
}


please help me in this issue.

Regards,
Dinesh
Sandeep Nair
RE: Dynamic Theme for organization in Liferay 5.1.2
January 12, 2011 2:40 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Is it giving errror. Just check if your theme id is correct too. Like the best way to check is first manually apply some other theme that is not classic and then in code apply the classic theme