Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Chris Whittle
My Places Portlet {RESOLVED}
February 16, 2009 4:11 PM
Answer

Chris Whittle

Rank: Expert

Posts: 462

Join Date: September 17, 2008

Recent Posts

Id like to take the my places that is on the dock and put it in a portlet and reformat it.... Has anyone done that or something similar?
relax sun
RE: My Places Portlet
February 5, 2009 2:39 AM
Answer

relax sun

Rank: Junior Member

Posts: 36

Join Date: June 21, 2007

Recent Posts

Hello,
I too am interested in a my places porltet.

H
Chris Whittle:
Id like to take the my places that is on the dock and put it in a portlet and reformat it.... Has anyone done that or something similar?


Are there news?

A starting point could be the my community portlet.

Regards
Victor Zorin
RE: My Places Portlet
February 6, 2009 12:34 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

We've made one and found that it is extremely popular with all clients. Based on MyPlaces but has few customisations, such as community icon, layout (horizontal/vertical), access rights, etc. I've made screendumps for 2 communities with our MyPlaces portlet deployed, here and here. Icons are defined using Community description field within Communities portlet.
Chris Whittle
RE: My Places Portlet
February 6, 2009 5:37 AM
Answer

Chris Whittle

Rank: Expert

Posts: 462

Join Date: September 17, 2008

Recent Posts

Any way we could talk you out of the source code? 8^)
Victor Zorin
RE: My Places Portlet
February 8, 2009 8:46 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

It is fairly straightforward, but I'll prepare and post some code extracts tonight (Aussie time).
Victor Zorin
RE: My Places Portlet
February 9, 2009 6:12 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

Below is an extract from the code.
JSP snippet, this one renders images and links of available (non-empty) communities for given user:
 1
 2<table>
 3    <logic:iterate id="thisPlace" name="staffPlacesList">
 4        <tr>
 5            <td valign="middle" align="right" style="padding: 2px">
 6            <logic:equal name="thisPlace" property="currentPlaceFlag" value="true">
 7            <img src="/myoffice-user/images/current_place.png" />
 8            </logic:equal>
 9            </td>
10            <td valign="middle" align="center" style="padding: 2px">
11                <a href="<bean:write name="thisPlace" property="placeUrl"/>">
12                <img border="0"
13                    src="<bean:write name="thisPlace" property="imageUrl"/>"/>
14                </a>
15            </td>
16            <td valign="middle" align="left" style="padding: 2px">
17                <a href="<bean:write name="thisPlace" property="placeUrl"/>">
18                    <bean:write name="thisPlace" property="placeName" />
19                </a>
20            </td>
21        </tr>
22    </logic:iterate>
23</table>

RenderAction snippet, a bit too long but self-explanatory:
 1
 2package com.myoffice.user.portlet.myplaces.action;
 3
 4// http://www.myoffice24x7.com
 5// ViewPlacesAction
 6
 7// ...
 8    public ActionForward render(ActionMapping mapping, ActionForm form,
 9            PortletConfig config, RenderRequest req, RenderResponse res)
10            throws Exception {
11        java.util.Collection<StaffPlaceBean> staffPlacesList = new java.util.ArrayList<StaffPlaceBean>();
12        if (req.getRemoteUser() != null) {
13            try {
14                long companyId = PortalUtil.getCompanyId(req);
15                long userId = PortalUtil.getUserId(req);
16                long currentGroupId = PortalUtil.getPortletGroupId(req);
17                LinkedHashMap groupParams = new LinkedHashMap();
18                groupParams.put("usersGroups", new Long(userId));
19                // find all communities for this user
20                java.util.List<Group> communities = GroupLocalServiceUtil
21                        .search(companyId, null, null, groupParams, -1, -1);
22                java.util.Iterator<Group> iterator = communities.iterator();
23                while (iterator.hasNext()) {
24                    Group community = (Group) iterator.next();
25                    if(community.getName().startsWith("Guest") == false)
26                    {
27                    StaffPlaceBean place = new StaffPlaceBean();
28                    if (community.getGroupId() == currentGroupId) {
29                        place.setCurrentPlaceFlag(true);
30                    } else {
31                        place.setCurrentPlaceFlag(false);
32                    }
33                    community = community.toEscapedModel();
34                    place.setPlaceName(community.getName());
35                    // fetch community icon url from its' description
36                    try {
37                        java.util.Properties props = new java.util.Properties();
38                        java.io.InputStream stream = new java.io.StringBufferInputStream(
39                                community.getDescription());
40                        props.load(stream);
41                        // logger.info("props=" + props);
42                        String imageUrl = props.getProperty("icon");
43                        if (imageUrl != null && imageUrl.length() > 0) {
44                            place.setImageUrl(imageUrl);
45                        } else {
46                            logger
47                                    .warn("Use community description to set 'icon=' for "
48                                            + community.getName());
49                            if (place.getCurrentPlaceFlag()) {
50                                place
51                                        .setImageUrl("/myoffice-user/images/default_place_selected.png");
52                            } else {
53                                place
54                                        .setImageUrl("/myoffice-user/images/default_place.png");
55                            }
56                        }
57                    } catch (Exception e) {
58                    }
59                    int publicCount = community.getPublicLayoutsPageCount();
60                    int privateCount = community.getPrivateLayoutsPageCount();
61                    if (publicCount > 0) {
62                        place.setPlaceUrl("/web" + community.getFriendlyURL());
63                        staffPlacesList.add(place);
64                    } else if (privateCount > 0) {
65                        place
66                                .setPlaceUrl("/group"
67                                        + community.getFriendlyURL());
68                        staffPlacesList.add(place);
69                    } else {
70                        logger.warn("Community '" + community.getName()
71                                + "' does not have any pages configured");
72                    }
73}
74                    else
75                    {
76                        // this is Guest community =, not to be displayed
77                    }
78                }
79            } catch (Exception e) {
80                e.printStackTrace();
81            }
82        }
83        req.setAttribute("staffPlacesList", staffPlacesList);
84        return mapping.findForward("view");
85    }               
Victor Zorin
RE: My Places Portlet
February 9, 2009 6:16 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

And for clarity, one more class, StaffPlaceBean:
 1
 2package com.myoffice.user.portlet.myplaces.form;
 3// http://www.myoffice24x7.com
 4// StaffPlaceBean
 5public class StaffPlaceBean {   
 6  private String placeUrl;   
 7  private String placeName;   
 8  private String imageUrl;   
 9  private boolean currentPlaceFlag = false;
10
11// ... getters and setters
12
13}
Chris Whittle
RE: My Places Portlet
February 10, 2009 8:43 AM
Answer

Chris Whittle

Rank: Expert

Posts: 462

Join Date: September 17, 2008

Recent Posts

ok I'm missing something... I'm able to get it to compile and display but it's not doing anything... It's probably due to my limited experience with struts and struts portlets but here is what I got... Maybe you can fill in the blank... Thanks again for your help(and code)!!!
liferay-portlet-ext.xml
 1<portlet>
 2        <portlet-name>my_places_display</portlet-name>
 3        <icon>/html/portlet/my_places_display/icon.png</icon>
 4        <struts-path>my_places_display</struts-path>
 5        <restore-current-view>false</restore-current-view>
 6        <private-request-attributes>false</private-request-attributes>
 7        <private-session-attributes>false</private-session-attributes>
 8        <render-weight>1</render-weight>
 9        <css-class-wrapper>portlet-my_places_display</css-class-wrapper>
10    </portlet>

Portlet-ext.xml
 1<portlet>
 2        <portlet-name>my_places_display</portlet-name>
 3        <display-name>My Places Display</display-name>
 4        <portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>
 5        <init-param>
 6            <name>view-action</name>
 7            <value>/my_places_display/view</value>
 8        </init-param>
 9        <expiration-cache>0</expiration-cache>
10        <supports>
11            <mime-type>text/html</mime-type>
12        </supports>
13        <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>
14        <security-role-ref>
15            <role-name>power-user</role-name>
16        </security-role-ref>
17        <security-role-ref>
18            <role-name>user</role-name>
19        </security-role-ref>
20    </portlet>

Struts-config.xml
1<action path="/my_places_display/view" type="com.ext.portlet.myplaces_display.ViewPlacesAction">
2            <forward name="portlet.my_places_display.view" path="portlet.my_places_display.view" />
3        </action>

Tiles-def.xml
1<definition name="portlet.my_places_display.view" path="/portlet/my_places_display/view.jsp" />


ViewPlacesAction.java
  1package com.ext.portlet.myplaces_display;
  2
  3import com.liferay.portal.struts.PortletAction;
  4import com.liferay.portal.model.Group;
  5import com.liferay.portal.service.GroupLocalServiceUtil;
  6import com.liferay.portal.util.PortalUtil;
  7
  8import java.util.LinkedHashMap;
  9
 10import javax.portlet.PortletConfig;
 11import javax.portlet.RenderRequest;
 12import javax.portlet.RenderResponse;
 13
 14import org.apache.struts.action.ActionForm;
 15import org.apache.struts.action.ActionForward;
 16import org.apache.struts.action.ActionMapping;
 17
 18import org.apache.commons.logging.Log;
 19import org.apache.commons.logging.LogFactory;
 20// http://www.myoffice24x7.com
 21// ViewPlacesAction
 22
 23public class ViewPlacesAction extends PortletAction {
 24    public ActionForward render(ActionMapping mapping, ActionForm form,
 25            PortletConfig config, RenderRequest req, RenderResponse res)
 26            throws Exception {
 27        java.util.Collection<StaffPlaceBean> staffPlacesList = new java.util.ArrayList<StaffPlaceBean>();
 28        if (req.getRemoteUser() != null) {
 29            try {
 30                long companyId = PortalUtil.getCompanyId(req);
 31                long userId = PortalUtil.getUserId(req);
 32                long currentGroupId = PortalUtil.getPortletGroupId(req);
 33                LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>();
 34                groupParams.put("usersGroups", new Long(userId));
 35                // find all communities for this user
 36                java.util.List<Group> communities = GroupLocalServiceUtil
 37                        .search(companyId, null, null, groupParams, -1, -1);
 38               java.util.Iterator<Group> iterator = communities.iterator();
 39                while (iterator.hasNext()) {
 40                    Group community = (Group) iterator.next();
 41                    if(community.getName().startsWith("Guest") == false)
 42                    {
 43                    StaffPlaceBean place = new StaffPlaceBean();
 44                    if (community.getGroupId() == currentGroupId) {
 45                        place.setCurrentPlaceFlag(true);
 46                    } else {
 47                        place.setCurrentPlaceFlag(false);
 48                    }
 49                    community = community.toEscapedModel();
 50                    place.setPlaceName(community.getName());
 51                    // fetch community icon url from its' description
 52                    try {
 53                        java.util.Properties props = new java.util.Properties();
 54                        java.io.InputStream stream = new java.io.StringBufferInputStream(community.getDescription());
 55                        props.load(stream);
 56                        // logger.info("props=" + props);
 57                        String imageUrl = props.getProperty("icon");
 58                        if (imageUrl != null && imageUrl.length() > 0) {
 59                            place.setImageUrl(imageUrl);
 60                        } else {
 61                            _log.warn("Use community description to set 'icon=' for "
 62                                            + community.getName());
 63                           if (place.getCurrentPlaceFlag()) {
 64                                place
 65                                        .setImageUrl("/myoffice-user/images/default_place_selected.png");
 66                            } else {
 67                                place
 68                                        .setImageUrl("/myoffice-user/images/default_place.png");
 69                            }
 70                        }
 71                    } catch (Exception e) {
 72                    }
 73                    int publicCount = community.getPublicLayoutsPageCount();
 74                    int privateCount = community.getPrivateLayoutsPageCount();
 75                    if (publicCount > 0) {
 76                        place.setPlaceUrl("/web" + community.getFriendlyURL());
 77                        staffPlacesList.add(place);
 78                    } else if (privateCount > 0) {
 79                        place
 80                                .setPlaceUrl("/group"
 81                                        + community.getFriendlyURL());
 82                        staffPlacesList.add(place);
 83                    } else {
 84                        _log.warn("Community '" + community.getName()
 85                                + "' does not have any pages configured");
 86                    }
 87}
 88                    else
 89                    {
 90                        // this is Guest community =, not to be displayed
 91                    }
 92                }
 93            } catch (Exception e) {
 94                e.printStackTrace();
 95            }
 96        }
 97        req.setAttribute("staffPlacesList", staffPlacesList);
 98       return mapping.findForward("portlet.my_places_display.view");
 99  }    
100    private static Log _log = LogFactory.getLog(ViewPlacesAction.class);
101
102}
Victor Zorin
RE: My Places Portlet
February 10, 2009 11:20 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

C'mon Chris the Jedi, you can do it!
My apologies, but I've got customised devel.environment and would not be able to do a quick replication of the setup that suits generic deployment. I might make simplified MyPlaces for public downloading, but not within several weeks.
Chris Whittle
RE: My Places Portlet
February 11, 2009 5:10 AM
Answer

Chris Whittle

Rank: Expert

Posts: 462

Join Date: September 17, 2008

Recent Posts

LOL, I know I'm so close... I'll keep messing with it and repost something if I can get it figured out.... Thanks again on the code Victor!!!
Victor Zorin
RE: My Places Portlet
February 14, 2009 4:23 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

Correction: If using jsp listed above, please add parameter filter="false" to every <bean:write/> tag.

This will prevent character escaping. Eg. if community name is 'Chris - Whittle', ie. contains dash, community name within MyPlaces would contain funky characters. Making filer=false will render it properly.
Chris Whittle
RE: My Places Portlet
February 16, 2009 4:14 PM
Answer

Chris Whittle

Rank: Expert

Posts: 462

Join Date: September 17, 2008

Recent Posts

thanks again Victor..... also what I had worked fine all along.. i had just killed my dev db and forgot to recreate my communities so all I had was the default organizations and the guest community (which to all you just tuning in don't show)...
Victor Zorin
RE: My Places Portlet
November 29, 2009 6:02 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

Public version of MyPlaces portlet has been placed into Liferay Community Plugins section.

To maintain a uniform 'single space' navigational and look-and-feel experience, reciprocal groupwise MyPlaces plugins are also under development for related web applications, such as Alfresco CMS, Bedework calendars, LMS, etc. Will give a link when demo deployments become available.
Chris Whittle
RE: My Places Portlet
November 30, 2009 7:25 AM
Answer

Chris Whittle

Rank: Expert

Posts: 462

Join Date: September 17, 2008

Recent Posts

Nice saw the screenshot and once we get to 5.2 we'll retire ours...
Hany Morris Mesha
RE: My Places Portlet
December 23, 2009 8:24 AM
Answer

Hany Morris Mesha

Rank: New Member

Posts: 4

Join Date: July 28, 2009

Recent Posts

I saw this portlet and it's wonderful. That's exactly what I was looking for. Can I use it with version 4.3?

Thanks,

Hany
Victor Zorin
RE: My Places Portlet
December 23, 2009 10:47 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

Hi Hany, there is no specific reliance on portal version features in a portlet, Portal Service APIs that are used in the portlet have not been modified substantially since v4 , but deployment have changed a bit. You may try to modify files in WEB-INF to lower the spec numbers and see if it deploys. I suppose a special backward build can be made for 4.3 but you would have to go through the ordering process.
Victor Zorin
RE: My Places Portlet
August 22, 2011 5:15 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

Downloads for MyPlaces portlet and associated hooks for Liferay V6.0.1+ and Liferay V6.1.0+ have been made available at http://www.myoffice24x7.com/web/myplaces-portlet. It will also be moved out from Liferay Plugins repository.
Akshata Joshi
My Places Portlet
August 25, 2011 3:59 AM
Answer

Akshata Joshi

Rank: New Member

Posts: 4

Join Date: August 25, 2011

Recent Posts

Hello,

I am a newbee for liferay.. i am currently using 4.2 version. I login as admin, click on MY Places --> Guest--> Private pages(1)....

it gets logout.. I am not able to fix this issue...

Please guide me.. It is a very critical iisue...

Thank you