Forums

Home » Liferay Portal » English » 3. Development »

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Liferay newbie needs help redirecting users to organisation landing pages Daniel M Scott July 7, 2009 4:36 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 7, 2009 10:18 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 8, 2009 2:41 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 8, 2009 6:10 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 8, 2009 6:19 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 8, 2009 7:05 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 8, 2009 7:37 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 8, 2009 8:06 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 8, 2009 2:24 PM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 8, 2009 3:04 PM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 9, 2009 4:05 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Victor Zorin July 9, 2009 5:16 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 9, 2009 9:00 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 9, 2009 11:41 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Daniel M Scott July 9, 2009 2:39 PM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 9, 2009 2:54 PM
RE: Liferay newbie needs help redirecting users to organisation landing pag srikanth arroju October 9, 2009 11:16 PM
RE: Liferay newbie needs help redirecting users to organisation landing pag Scott Gibson August 4, 2009 9:33 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Vidya Sagar Padigela August 4, 2009 10:11 AM
RE: Liferay newbie needs help redirecting users to organisation landing pag Victor Zorin August 4, 2009 3:18 PM
RE: Liferay newbie needs help redirecting users to organisation landing pag Arvind Mishra July 9, 2009 6:47 AM
Daniel M Scott
Liferay newbie needs help redirecting users to organisation landing pages
July 7, 2009 4:36 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Guys

Hoping one of you can help me out, im new to liferay and JAVA, i'm vb.net normally but after finding liferay by chance i love it and its much better than .net nuke out of the box (in my opinion) anyway ive been able to use the help articles and learnt some cool stuff so far, but now im stuck.

I have many organisations in my company and what id like to do is is redirect them to the organsation landing page when they login depending on what organisations they belong to. (in some isntances it could be many i know but ill handle that with an if statement)

I have seen this post but its left me with some questions. post

1) Am i right in thinking that i just need to update the code here in notepad and save it?
portal-impl/src/com/liferay/portal/events/DefaultLandingPageAction.java
2)How can i get the organisation the user belongs to programmatically
3)How would i structure the if statment to determine where to redirect them to, for example in vb.net i could do it like

If user.organisation = "Business" then
Response.redirect("blabala"

Any help would be greatly appreciated as im alittle stuck on what to update where, and what code i need to actually achieve the desired result

Thanks in advance

Dan
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 7, 2009 10:18 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

There are two steps involved here -

1) If a user has to access an organization , user should belong to that organization
there are two ways to do that -
a) Either do programmatically , when user is registering based on some condition , you can drop user to a particluar organization .
b) Admin can also drop a user to a particular organization through admin portlet .


2) Redirecting user to respective organization .
You can achieve this by writing your code in DefaultLandingPageAction.java

Now to your questions -

1) Am i right in thinking that i just need to update the code here in notepad and save it?
portal-impl/src/com/liferay/portal/events/DefaultLandingPageAction.java


If you are building directly from source code , you can do the way you mentioned . Otherwise you have to add DefaultLandingPageAction.java to you ext code in following directory ext-impl/src/com/liferay/portal/events/DefaultLandingPageAction.java


2)How can i get the organisation the user belongs to programmatically

User this code to fetch User's Organization

      List<Organization>  userOrganizations = null ;
      userOrganizations  = OrganizationLocalServiceUtil.getUserOrganizations(userId);


You can iterate through this list to find all the organization user belongs to.

3)How would i structure the if statment to determine where to redirect them to, for example in vb.net i could do it like

Here is the sample code to redirect the User based on Organzation - It will go inside run() method of DefaultLandingPageAction.java


String forwardURL = "";

if(USER_BELONGS_TO_ORGA){
     forwardURL  =  "group/ORGA/home";
elseif(){
    // Complete the conditions.
}else{

    // Complete the conditions.
}

// This code is commented at the end of the method . I modified it a bit .
if(forwardurl !=null  && !forwardurl.equals(StringPool.BLANK)){
            LastPath lastPath = new LastPath(StringPool.BLANK, forwardurl  , new HashMap<String, String[]>());
   
            session.setAttribute(WebKeys.LAST_PATH, lastPath);
}


Hope this helps

Thanks
Arvind
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 2:41 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Arvind

Thanks so much for your help so far, but i have a few more questions.

I am using netbeans and have downloaded the source code for liferay, i have copied the file DefaultLandingPageAction.JAVA and renamed it CustomLandingPageAction.JAVA

I have written this code so far:

public class CustomLandingPageAction extends Action {

public void run(HttpServletRequest request, HttpServletResponse response) {
String userId = request.getRemoteUser();
User user = UserLocalServiceUtil.getUserById(Long.parseLong(userId));
List<Organization> userOrganizations = null;
userOrganizations = OrganizationLocalServiceUtil.getUserOrganizations(Long.parseLong(userId));

Is this correct so far? as i am getting an error message "unreported exception com.liferay.portal.PortalException; must be caught or declared to be thrown

I am not quite sure what this means, can you advise.

Thanks in advance.
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 6:10 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

Because the methods in LocalServiceUtils throw this exceptions .
You can handle them like this


User user = null;
try{
    user = UserLocalServiceUtil.getUserById(Long.parseLong(userId));
}catch(Exception e1)
{
   e1.printStackTrace();
}
List<Organization> userOrganizations = null;

try{
      userOrganizations = OrganizationLocalServiceUtil.getUserOrganizations(Long.parseLong(userId));
}catch(Exception e2)
{
   e2.printStackTrace();
}
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 6:19 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Arvind

Thanks for all your help, I came up with this, was going to let you know, i realised i needed a try catch block after doing some searching online, does this code look right to you?

package com.liferay.portal.events;

import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
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.kernel.util.StringPool;
import com.liferay.portal.struts.LastPath;

import java.util.HashMap;
import java.util.List;
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="CustomLandingPageAction.java.html"><b><i>View Source</i></b></a>
*
* @author Dan Scott
*
*/
public class CustomLandingPageAction extends Action {

public void run(HttpServletRequest request, HttpServletResponse response) {

String userId = request.getRemoteUser();
String forwardUrl = "";
try
{
User 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);
}
for (int i = 0; i < organizations.size(); i++)
{
Organization organization = (Organization) organizations.get(i);

}
if (organizations.contains("Consumer")){
forwardUrl = "web/consumer";
}
else if (organizations.contains("Business")){
forwardUrl = "web/business";
}
else if (organizations.contains("Team Leader")){
forwardUrl = "web/teamleader";
}
else if (organizations.contains("Technical")){
forwardUrl = "web/technical";
}
else
{
forwardUrl = "web/consumer";
}

if(forwardUrl !=null && !forwardUrl.equals(StringPool.BLANK)){
LastPath lastPath = new LastPath(StringPool.BLANK, forwardUrl , new HashMap<String, String[]>());

HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
}
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 7:05 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

Hi Dan

Code is fine . But there is one thing . Although you have declared the "user" variable , you are not using it any where. But later on if you want to use this variable you have to change your code .

User user = 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);
}


Thanks
Arvind
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 7:37 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Arvind

Thanks for pointing that out, ill change it now, 1 more piece of advice if you wouldnt mind,

I am running the liferay tomcat bundle. not from source code, i have also downloaded th source which i am opening with netbeans ide. I have created the code in the liferay source within netbeans ide.

How can i now get this inside the tomcat bundle, do i do one of the following:

1) Simply copy my JAVA file and paste it inside the current tomcat bundle jar file
C:\liferay-portal-5.2.3\tomcat-6.0.18\webapps\ROOT\WEB-INF\lib\portal-impl
2) do i need to compile the file or build it or something like this
3) do i need to complie all my Liferay source code and then take the compiled JAR of C:\liferay-portal-5.2.3\tomcat-6.0.18\webapps\ROOT\WEB-INF\lib\portal-impl and put this inside my liferay tomcat bundle?

Can you advise, im alittle confused as i havent done this before.

Thanks in advance.
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 8:06 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

You need to compile source code and place portal-impl.jar inside webapps\ROOT\WEB-INF\lib

thanks
Arvind
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 2:24 PM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Arvind

That worked, and it compiled fine, however the code doesnt seem to work, once i login it comes up with a html page cannot be displayed message.

I have tried this code,

public class CustomLandingPageAction extends Action {

public void run(HttpServletRequest request, HttpServletResponse response) {

String userId = request.getRemoteUser();
String forwardUrl = "";
User user = 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);
}
for (int i = 0; i < organizations.size(); i++)
{
Organization organization = (Organization) organizations.get(i);

}
if (organizations.contains("Consumer")){
forwardUrl = "web/consumer";
}
else if (organizations.contains("Business")){
forwardUrl = "web/business";
}
else if (organizations.contains("Team Leader")){
forwardUrl = "web/teamleader";
}
else if (organizations.contains("Technical")){
forwardUrl = "web/technical";
}
else
{
forwardUrl = "web/consumer";
}

if(forwardUrl !=null && !forwardUrl.equals(StringPool.BLANK)){
LastPath lastPath = new LastPath(StringPool.BLANK, forwardUrl , new HashMap<String, String[]>());

HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
}
And also this

public class CustomLandingPageAction2 extends Action {

public void run(HttpServletRequest request, HttpServletResponse response) {

String userId = request.getRemoteUser();
String forwardUrl = "";
User user = 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);
}
for (int i = 0; i < organizations.size(); i++)
{
Organization organization = (Organization) organizations.get(i);

}
if (organizations.contains("Consumer")){
forwardUrl = "/web/consumer/home";
}
else if (organizations.contains("Business")){
forwardUrl = "/web/business/home";
}
else if (organizations.contains("Team Leader")){
forwardUrl = "/web/teamleader/home";
}
else if (organizations.contains("Technical")){
forwardUrl = "/web/technical/home";
}
else if (organizations.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);

}
}

Both have the same result, page cannot be displayed. Is there a way for me to debug this and step through so i can actually evaluate if once i click submit its actually evaulating the conditions and then see whats happing with the redirect.
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 8, 2009 3:04 PM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

after this add the print statement

if (organizations.contains("Consumer")){
forwardUrl = "web/consumer";
}
else if (organizations.contains("Business")){
forwardUrl = "web/business";
}
else if (organizations.contains("Team Leader")){
forwardUrl = "web/teamleader";
}
else if (organizations.contains("Technical")){
forwardUrl = "web/technical";
}
else
{
forwardUrl = "web/consumer";
}

to see what is forward URL

System.out.println("Forward URL is :" + forwardUrl );
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 4:05 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Arvind

I managed to setup netbeans to debug my code, works very well. Basically from what i can see it doesnt seem to find the values inside the organisation list array, it creates the list as an arraylist and adds many values about the organisation into it as there is only one organisation for this user it sets the array at [0]. it then adds the organisation id, name, parent ogranisationid, name etc etc. I thought organisation.contains("Business") would pick up the string value business from the name, but this doesnt seem to be the case.

Any ideas?
Victor Zorin
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 5:16 AM
Answer

Victor Zorin

Rank: Liferay Master

Posts: 985

Join Date: April 14, 2008

Recent Posts

Daniel, have a look at another way of setting landing page for each user individually. This one will forward user to private pages of a specific community when user's 'Comments' field has the following line:
default.landing.group=Community Name

You can make something similar, adjust action class to suit your requirements. Source code will be inside the dowloaded jar file. Here is the link.
.
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 6:47 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

Oh , i missed that part in your earlier code ...

organizations is an array list containing Organization Object . so when you will do organizations.contains("ABC") , this condition will fail.

You can do one thing . Create one more list and add all the names in to that list .

List<String>  userOrgName =  new List();

for (int i = 0; i < organizations.size(); i++)
{
Organization organization = (Organization) organizations.get(i);
userOrgName .add(organization .getName());

}


Then check the forward string against new list

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";
}

}
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 9:00 AM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

Hi Victor

Thank you for the suggested solution, it looks very promising and if i cannot get this to work i might look at using this. My only concern with it is with a potential 1000 users it could become very difficult to manage as id have to assign each users default individually, my aim was to use the organisation they belonged to as it meant i could direct them on mass and would be easier when they move organisations etc.

Arvind, i have just updated the code and it works to the point where it should be taking the user to the page, see the attached screen shot of my debug in net beans, and then the screen shot of my page cannot be displayed, it assigns the lath path variable to my website addresss but then it seems not to find the page.

Any ideas?
Attachment

Attachment

Attachments: Untitled-1.gif (92.5k), Untitled-2.gif (47.8k)
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 11:41 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

Does that URL exists . I mean , can the logged in user access http://localhost:8080/web/consumer/home
Daniel M Scott
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 2:39 PM
Answer

Daniel M Scott

Rank: Junior Member

Posts: 51

Join Date: July 7, 2009

Recent Posts

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);
}
Arvind Mishra
RE: Liferay newbie needs help redirecting users to organisation landing pag
July 9, 2009 2:54 PM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 217

Join Date: February 13, 2008

Recent Posts

That's great news Daniel .

Patience is the virtue.

Thanks
Arvind
Scott Gibson
RE: Liferay newbie needs help redirecting users to organisation landing pag
August 4, 2009 9:33 AM
Answer

Scott Gibson

Rank: New Member

Posts: 19

Join Date: June 12, 2009

Recent Posts

Victor Zorin:
Daniel, have a look at another way of setting landing page for each user individually. This one will forward user to private pages of a specific community when user's 'Comments' field has the following line:
default.landing.group=Community Name

You can make something similar, adjust action class to suit your requirements. Source code will be inside the dowloaded jar file. Here is the link.
.


How would I modify this to send the user to the respective public page of the community rather than the private?
Vidya Sagar Padigela
RE: Liferay newbie needs help redirecting users to organisation landing pag
August 4, 2009 10:11 AM
Answer

Vidya Sagar Padigela

Rank: Junior Member

Posts: 47

Join Date: May 20, 2008

Recent Posts

Scott Gibson:
Victor Zorin:
Daniel, have a look at another way of setting landing page for each user individually. This one will forward user to private pages of a specific community when user's 'Comments' field has the following line:
default.landing.group=Community Name

You can make something similar, adjust action class to suit your requirements. Source code will be inside the dowloaded jar file. Here is the link.
.


How would I modify this to send the user to the respective public page of the community rather than the private?


I did using the following way.



public class CommunityDefaultLandingPageAction 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);
        }

                        
        User user = null;
        String forwardURL = null;
        Group group= null;
        try{
            user = PortalUtil.getUser(request);
            long  groupIds[] = user.getGroupIds();
            
            for(int i =0;i<groupIds.length; i++){
                long groupId  = groupIds;
                group = GroupLocalServiceUtil.getGroup(groupId);
                if(group.getName().equalsIgnoreCase("SSC")){
                    forwardURL = "/web/ssc/home";
                    break;
                }
            }
            
       
        }catch(Exception e){

        }
       
        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);

   
        }

        // The commented code shows how you can programmaticaly set the user's
        // landing page. You can modify this class to utilize a custom algorithm
        // for forwarding a user to his landing page. See the references to this
        // class in portal.properties.

        /*Map<String, String[]> params = new HashMap<String, String[]>();

        params.put("p_l_id", new String[] {"1806"});

        LastPath lastPath = new LastPath("/c", "/portal/layout", params);

        ses.setAttribute(WebKeys.LAST_PATH, lastPath);*/
   

    private static Log _log =
         LogFactoryUtil.getLog(SSCCommunityDefaultLandingPageAction.class);

}


Thanks,
Vidya Padigela
Victor Zorin
RE: Liferay newbie needs help redirecting users to organisation landing pag
August 4, 2009 3:18 PM
Answer

Victor Zorin

Rank: Liferay Master

Posts: 985

Join Date: April 14, 2008

Recent Posts

Change:
group.getDefaultPrivatePlid()
to
group.getDefaultPublicPlid()
srikanth arroju
RE: Liferay newbie needs help redirecting users to organisation landing pag
October 9, 2009 11:16 PM
Answer

srikanth arroju

Rank: Regular Member

Posts: 115

Join Date: October 2, 2009

Recent Posts

Hello Arvind,
i want the users to veiw their landing page based on the usergroups they belong to
how can i achieve this in lifray?

Thanks,
Srikanth