2013-02-04 112 views

回答

2

我最終實現了自己的代碼。而不是使用liferay inbuild功能。 1.這裏是我的文件的Jsp代碼。

//Page Imports & taglibs 
    <%@page import="com.liferay.portal.service.persistence.UserTrackerPathUtil"%> 
    <%@page import="com.liferay.portal.service.UserLocalServiceUtil"%> 
    <%@page import="com.liferay.portal.service.UserTrackerPathLocalServiceUtil"%> 
    <%@page import="com.liferay.portal.service.UserTrackerLocalServiceUtil"%> 
    <%@page import="com.liferay.counter.service.CounterLocalServiceUtil" %> 
    <%@page import="com.liferay.portal.util.PortalUtil" %> 
    <%@page import="java.util.ArrayList"%> 
    <%@page import="com.liferay.portal.model.UserTracker" %> 
    <%@page import="com.liferay.portal.model.UserTrackerPath" %> 
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%> 
    <%-- <%@include file="/html/demo/one.jsp" %> --%> 

    <theme:defineObjects/> 
    // Define theme object to get user and other basic information 
    <% 
    HttpSession http_session = request.getSession(); 
    //Get the current session variable. 

    String id = http_session.getId(); 
    //Getting id of session 
     String path = themeDisplay.getLayout().getFriendlyURL(); 
    //Getting path that will be stored in path field of UserTrackerPath table. 
     System.out.println("***==> Current Url => "+ themeDisplay.getURLCurrent()); 
    //path = path.substring(path.lastIndexOf("/")); 
    String localhostname = java.net.InetAddress.getLocalHost().getHostName(); 
     //Getting the localhost name of machine from which user is acccessing site 
    String ipAddress = java.net.InetAddress.getLocalHost().getHostAddress(); 
     //Getting ip address of machine, In case of if user is using an proxy env you may need some other efforts to get exact ip. 
     if(ipAddress == null) 
     { 
      ipAddress = request.getRemoteAddr(); 
     } 
    try { 
      UserTracker user_tracker =  (UserTracker)http_session.getAttribute("user_tracker"); 
    //Now when user session creates for first time then you need to add an entry in UserTracker table and all the rest entries for path traversal are need to be added at UserTrackerPath with new userTrackerPathId and userTrackerId as foreignkey. 
      if(user_tracker == null) 
      { 
        UserTracker tracker = null; 
        ArrayList<UserTrackerPath> userTrackerPath = new ArrayList<UserTrackerPath>(); 
    //Create an Array List of UserTrackerPath needs to be added in method of addUserTracker by UserTrackerLocalServiceUtil 
        UserTrackerPath utp= null; 
        utp = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment()); 

        utp.setPath(path); 
        utp.setPathDate(new java.util.Date()); 
        userTrackerPath.add(utp); 
    //Add an entry to array list     
      tracker = UserTrackerLocalServiceUtil.addUserTracker(themeDisplay.getCompanyId(), 
          themeDisplay.getUserId(), 
          new java.util.Date(), 
          id, 
          ipAddress, 
          localhostname, 
          userAgent, 
          userTrackerPath); 
    //UserTracker will be added to database 
        http_session.setAttribute("user_tracker",tracker); 
     //Adds value to session to check that next time session is null or not, so that it can decide whether to execute code of if or else. 
      } 
      else 
      { 
    //If session is not null then you already have an entry in UserTracker and you need to keep path track in UserTarckerPath Table 
       UserTrackerPath utp = UserTrackerPathLocalServiceUtil.createUserTrackerPath(CounterLocalServiceUtil.increment()); 
       utp.setUserTrackerId(user_tracker.getUserTrackerId()); 
       utp.setPath(path); 
       utp.setPathDate(new java.util.Date()); 
       utp =  UserTrackerPathLocalServiceUtil.updateUserTrackerPath(utp, true); 
    //Update path 
      } 

    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 

    %> 
  • 所以現在去你portal-ext.properties及以下屬性

    session.tracker.persistence.enabled=true 
    
    live.users.enabled=false 
    
    session.tracker.ignore.paths=\/portal/render_portlet,\/document_library/get_file 
    
  • 一旦完成包括jsp中添加到您的主題portal-normal.vm,使其得到入店每一個地方。看看 Add a global Jsp to include in Liferay tomcat-6 ,它會成功將追蹤的數據添加到表中。 :)

  • 注意:如果在CE中有任何其他替代方法,很高興收到您對此的建議。 謝謝:)

    相關問題