Hi Victor and Arvind
Got the code working, here it is, im going to post it up for everyone incase someone else ever needs it, the reason it wasnt working is due to the missing params that the original tutorial had in which i left out, including them and it works fine.
I might post this up on a seperate item as ive seen others ask how to do it before and not sure they;ll find it here,
Thank you Victor for your suggested solution and a big thank you Arvind as without you i wouldnt have been able to do this
/**
* Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.liferay.portal.events;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.util.WebKeys;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.struts.LastPath;
import com.liferay.portal.util.PropsKeys;
import com.liferay.portal.util.PropsValues;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* <a href="CustomLandingPageAction2.java.html"><b><i>View Source</i></b></a>
*
* @author Dan Scott
*
*/
public class CustomLandingPageAction2 extends Action {
public void run(HttpServletRequest request, HttpServletResponse response) {
String path = PropsValues.DEFAULT_LANDING_PAGE_PATH;
if (_log.isInfoEnabled()) {
_log.info(
PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path);
}
String userId = request.getRemoteUser();
String forwardUrl = "";
User user = null;
String orgname = null;
try
{
user = UserLocalServiceUtil.getUserById(Long.parseLong(userId));
}
catch (PortalException ex)
{
Logger.getLogger(CustomLandingPageAction.class.getName()).log(Level.SEVERE, null, ex);
}
catch (SystemException ex)
{
Logger.getLogger(CustomLandingPageAction.class.getName()).log(Level.SEVERE, null, ex);
}
List organizations = null;
try
{
organizations = OrganizationLocalServiceUtil.getUserOrganizations(Long.parseLong(userId));
}
catch (SystemException ex)
{
Logger.getLogger(CustomLandingPageAction.class.getName()).log(Level.SEVERE, null, ex);
}
List<String> userOrgName = new ArrayList<String>();
for (int i = 0; i < organizations.size(); i++)
{
Organization organization = (Organization) organizations.get(i);
userOrgName .add(organization .getName());
}
if (userOrgName.contains("Consumer")){
forwardUrl = "/web/consumer/home";
}
else if (userOrgName.contains("Business")){
forwardUrl = "/web/business/home";
}
else if (userOrgName.contains("Team Leader")){
forwardUrl = "/web/teamleader/home";
}
else if (userOrgName.contains("Technical")){
forwardUrl = "/web/technical/home";
}
else if (userOrgName.contains("Sales")){
forwardUrl = "/web/sales/home";
}
else
{
forwardUrl = "/web/consumer/home";
}
HttpSession session = request.getSession();
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("p_l_id", new String[] {"1806"});
LastPath lastPath = new LastPath(StringPool.BLANK, forwardUrl, params);
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
private static Log _log =
LogFactoryUtil.getLog(CustomLandingPageAction2.class);
}
Please sign in to flag this as inappropriate.