Foren

How to fetch companyId and groupID in theme vm file

thumbnail
Subhasis Roy, geändert vor 12 Jahren.

How to fetch companyId and groupID in theme vm file

Expert Beiträge: 275 Beitrittsdatum: 20.01.12 Neueste Beiträge
hi,

can any one please tell me that how can I fetch group Id and company Id in portal_normal.vm file and also how to import service classes in theme vm file?
thumbnail
Jitendra Rajput, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
You can access Liferay services inside VM files .

check this link .--> http://itsliferay.blogspot.in/2012/01/use-of-liferay-service-in-velocity-file.html


And to get company id and group id in velocity file ..

($request.get("theme-display").get("company-id"))


($request.get("theme-display").get("scope-group-id"))
thumbnail
amit doshi, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Liferay Master Beiträge: 550 Beitrittsdatum: 29.12.10 Neueste Beiträge
Hi,

There is no need to fetch Company Id and GroupId in portal_normal.vm
You will directly get using $company_id and $group_id.

For more information please refer the url http://www.liferay.com/community/wiki/-/wiki/Main/Access+Objects+from+Velocity

In order to access service, you can use the following way :-

The below is the example for JournalArticle Service.
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))


Hope it helps.

Thanks & Regards,
Amit Doshi
thumbnail
Subhasis Roy, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Expert Beiträge: 275 Beitrittsdatum: 20.01.12 Neueste Beiträge
amit doshi:
Hi,

The below is the example for JournalArticle Service.
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))




I have created one custom service util class(MyUserExtLocalServiceUtil).

Then I tried to access the class in vm file using following code.

#set ($myUserExtLocalServiceUtil = $serviceLocator.findService("com.test.service.MyUserExtLocalServiceUtil"))
#set ($my_list = $myUserExtLocalServiceUtil.findByGroupId(10959))


But that code did not work. Because its not able to import my custom util class
thumbnail
Jitendra Rajput, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
set the below property in portal-ext and then try

 journal.template.velocity.restricted.variables=
thumbnail
amit doshi, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Liferay Master Beiträge: 550 Beitrittsdatum: 29.12.10 Neueste Beiträge
Hi Roy,

You are trying to access the util class with the serviceLocator, it will not work.

you need to access the Service Class for it.

I modified your code.


#set ($myUserExtLocalServiceUtil = $serviceLocator.findService("com.test.service.MyUserExtLocalService"))
#set ($my_list = $myUserExtLocalServiceUtil.findByGroupId(10959))


Hope it works now.

Regards,
Amit Doshi
thumbnail
Jitendra Rajput, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
If i am not wrong then we can also access findservice in this way .

#set ($customLocalService = $serviceLocator.findService('Custom-portlet', 'com.test.service.CustomLocalService'))


Where the first argument is portlet id .
thumbnail
Subhasis Roy, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Expert Beiträge: 275 Beitrittsdatum: 20.01.12 Neueste Beiträge
amit doshi:
Hi Roy,

You are trying to access the util class with the serviceLocator, it will not work.

you need to access the Service Class for it.
I modified your code.


#set ($myUserExtLocalServiceUtil = $serviceLocator.findService("com.test.service.MyUserExtLocalService"))
#set ($my_list = $myUserExtLocalServiceUtil.findByGroupId(10959))


Hope it works now.

Regards,
Amit Doshi



Hi Amit,

Let me tell you what I did till now.

I created my custom ext service for "AssetEntry" table of liferay and put the jar files in proper location.
ext-service.jar inside "liferay\tomcat-7.0.25\lib\ext"
rest of the jars(ext-impl.jar,ext-util-bridges.jar,ext-util-java.jar,ext-util-taglib.jar) files I put under "\webapps\ROOT\WEB-INF\lib"

Then I put the following code in my init_custom.vm file
#set ($myUserExtLocalServiceUtil = $serviceLocator.findService("com.test.service.MyUserExtLocalService"))
#set ($my_list = $myUserExtLocalServiceUtil.findByGroupId(10959))

In portal_normal.vm file I tried to access the my_list variable
<p>$my_list</p>


But it showing me the following error :


INFO: Reloading context [/JoinNALife-theme]
10:19:44,443 INFO [PluginPackageUtil:1026] Reading plugin package for JoinNALife-theme
10:19:44,490 INFO [ThemeHotDeployListener:172] Registering themes for JoinNALife-theme
10:19:46,506 INFO [ThemeHotDeployListener:100] 1 theme for JoinNALife-theme is available for use
10:19:58,114 ERROR [ServiceLocator:39] com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefi
nitionException: No bean named 'com.test.service.MyUserExtLocalService' is defined
com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.tes
t.service.MyUserExtLocalService' is defined
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:80)
at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:80)
at com.liferay.portal.velocity.ServiceLocator.findService(ServiceLocator.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)
at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:507)
at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71)
at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142)
thumbnail
Subhasis Roy, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Expert Beiträge: 275 Beitrittsdatum: 20.01.12 Neueste Beiträge
I used the following code

#set ($joinNALifeUserExtLocalServiceUtil = $utilLocator.findUtil("com.joinnalife.asset.entry.service.JoinNALifeUserExtLocalServiceUtil"))
#set ($my_list2 = $joinNALifeUserExtLocalServiceUtil.findByGroupId(10959))

I have used the utilLocator.findUtil

Its showing me the following console error:

12:02:29,040 ERROR [UtilLocator:39] com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinit
ionException: No bean named 'com.joinnalife.asset.entry.service.JoinNALifeUserExtLocalServiceUtil' is defined
com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.joi
nnalife.asset.entry.service.JoinNALifeUserExtLocalServiceUtil' is defined
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:80)
at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:80)
at com.liferay.portal.velocity.UtilLocator.findUtil(UtilLocator.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)
at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:507)
Siby Mathew, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Expert Beiträge: 268 Beitrittsdatum: 04.03.11 Neueste Beiträge
Hi Subhasis,
If you want to invoke Liferay in-built Services, you need to call

#set ($liferayLocalService = $serviceLocator.findService("com.liferay.portal.service.SomeLiferayLocalService"))


This will internally call PortalBeanLocatorUtil to locate the liferay service.

If you want to invoke a custom service in your portlet, you need to call

#set ($customLocalService = $serviceLocator.findService("Custom-portlet", "com.my.service.CustomLocalService"))


This will internally invoke the PortletBeanLocatorUtil to locate using the portlet name.

Thanks,
Siby
thumbnail
amit doshi, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

Liferay Master Beiträge: 550 Beitrittsdatum: 29.12.10 Neueste Beiträge
Hi Subhasis,

I agree with Jitendra and Siby Mathew

#set ($customLocalService = $serviceLocator.findService("Custom-portlet", "com.my.service.CustomLocalService"))


But also need to put that particular service jar in <TOMCAT_HOME>/ext/lib/ then only you will be access the service.

Hope it helps.

Thanks & Regards,
Amit Doshi
Prashant Deshpande, geändert vor 12 Jahren.

RE: How to fetch companyId and groupID in theme vm file

New Member Beiträge: 16 Beitrittsdatum: 17.06.10 Neueste Beiträge
Use these variables directly as
$group_id => will give you groupId
$company_id => Will give you company id

These are in build variables like request, you will get values at run time