Fórumok
display organization custom attribute in portlet
Martin ALFONSI, módosítva 8 év-val korábban
display organization custom attribute in portlet
New Member Bejegyzések: 9 Csatlakozás dátuma: 2015.06.23. Legújabb bejegyzések
Hi,
I'm new to Liferay and have to work on a platform which have been developed by someone else (so I don't really know how everything was done during first devlopment..).
On this platform, organizations have a custom attribute named "label", which is set by a regular admin. Each organizations have a site, and I have a portlet for them to display their informations. I would like to display this organization label on this portlet, but I don't know how... The field must only be displayed, not editable.
I did some research and find examples of user attributes, but I don't know how to adapt them correctly to an organization's attribute, as I have currenlty no organization variable in the portlet.
Example I found :
Anybody can help me plz ?
I'm new to Liferay and have to work on a platform which have been developed by someone else (so I don't really know how everything was done during first devlopment..).
On this platform, organizations have a custom attribute named "label", which is set by a regular admin. Each organizations have a site, and I have a portlet for them to display their informations. I would like to display this organization label on this portlet, but I don't know how... The field must only be displayed, not editable.
I did some research and find examples of user attributes, but I don't know how to adapt them correctly to an organization's attribute, as I have currenlty no organization variable in the portlet.
Example I found :
<liferay-ui:custom-attribute className="<%= User.class.getName() %>" classPK="<%= selUser != null ? selUser.getUserId() : 0 %>" editable="<%= false %>" name="Qualification" label="true" />
Anybody can help me plz ?
Pankaj Kathiriya, módosítva 8 év-val korábban
RE: display organization custom attribute in portlet
Liferay Master Bejegyzések: 722 Csatlakozás dátuma: 2010.08.05. Legújabb bejegyzések
You can get organizationId of Organization associated with site. As you will have access to themeDisplay object in your jsp (using liferay-theme.tld), you can use code below to get organizationId.
themeDisplay.getScopeGroup().getOrganizationId()
Martin ALFONSI, módosítva 8 év-val korábban
RE: display organization custom attribute in portlet
New Member Bejegyzések: 9 Csatlakozás dátuma: 2015.06.23. Legújabb bejegyzések
Hi Pankai,
I'm sorry but your code always return 0....
I manage to find an other code which is suppose to get the organization id :
Thanks to the system.out, I find that currentGroup is consider as Community, but anyway both getGroupId and getClassPK return the same ID.
The problem is that this ID is the Site ID, not the Organization... Indeed if I try to get the Organization with OrganizationLocalServiceUtil.getOrganization(organizationId) I get an exception "no organization exists with the primary key 3252218"
I thought I could get it from the website, but WebsiteLocalServiceUtil.getWebsite(organizationId) also return me the NoSuchWebsiteException: No Website exists with the primary key 3252218
Any help plz ?
I'm sorry but your code always return 0....
I manage to find an other code which is suppose to get the organization id :
com.liferay.portal.model.Group currentGroup = themeDisplay.getLayout().getGroup();
if (currentGroup.isOrganization()){
organizationId = currentGroup.getClassPK();
System.out.println("orga");
} else if (currentGroup.isCommunity()) {
organizationId = currentGroup.getGroupId();
System.out.println("not orga");
Thanks to the system.out, I find that currentGroup is consider as Community, but anyway both getGroupId and getClassPK return the same ID.
The problem is that this ID is the Site ID, not the Organization... Indeed if I try to get the Organization with OrganizationLocalServiceUtil.getOrganization(organizationId) I get an exception "no organization exists with the primary key 3252218"
I thought I could get it from the website, but WebsiteLocalServiceUtil.getWebsite(organizationId) also return me the NoSuchWebsiteException: No Website exists with the primary key 3252218
Any help plz ?
Harish Kumar, módosítva 8 év-val korábban
RE: display organization custom attribute in portlet
Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzésekThanks to the system.out, I find that currentGroup is consider as Community, but anyway both getGroupId and getClassPK return the same ID.
It clearly states that your portlet is placed on a site page and site is not an organization site but normal. So is you are getting
The problem is that this ID is the Site ID, not the Organization... Indeed if I try to get the Organization with OrganizationLocalServiceUtil.getOrganization(organizationId) I get an exception "no organization exists with the primary key 3252218"
If you are on organization site then below code snippet will do the job
if (currentGroup.isOrganization()){
System.out.println("orga");
try {
System.out.println(OrganizationLocalServiceUtil.getOrganization(currentGroup.getOrganizationId()).getName());
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Martin ALFONSI, módosítva 8 év-val korábban
RE: display organization custom attribute in portlet
New Member Bejegyzések: 9 Csatlakozás dátuma: 2015.06.23. Legújabb bejegyzések
Hi Harish,
Maybe I don't explain well, but the currentGroup is consider as Community, NOT organization, so your code won't go in your if statement.
If I remove your if statment, currentGroup.getOrganizationId() return 0, so I get the exception again...
And I think my site is indeed linked to the orgonization : if I go on the organization edit page in the control panel, the "site id" field is the one from the page I'm looking.
But it looks like the site is linked strangely, because if I go to the "Organization Site" sub-menu, I see no site and only the "create site" button.
If I check it and create a new site with my template, there is my portlet (with my code to display the label WORKING !) but all other fields my portlet is supposed to show doesn't appear...
Looking at the rest of the code, it looks like informations are taken from a ClusterProfileModel which doesn't contain the label...
Maybe I don't explain well, but the currentGroup is consider as Community, NOT organization, so your code won't go in your if statement.
If I remove your if statment, currentGroup.getOrganizationId() return 0, so I get the exception again...
And I think my site is indeed linked to the orgonization : if I go on the organization edit page in the control panel, the "site id" field is the one from the page I'm looking.
But it looks like the site is linked strangely, because if I go to the "Organization Site" sub-menu, I see no site and only the "create site" button.
If I check it and create a new site with my template, there is my portlet (with my code to display the label WORKING !) but all other fields my portlet is supposed to show doesn't appear...
Looking at the rest of the code, it looks like informations are taken from a ClusterProfileModel which doesn't contain the label...
ClusterProfile model = (ClusterProfile) request.getAttribute("clusterProfileModel");