Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to access custom service in webcontent in liferay dxp
Hi Experts,
We have developed one module based liferay service, having my custom table defined in service.xml(UserTutorial),
user-tutorial
--> user-tutorial-api
-->user-tutorial-service
Everything is fine so far.
Now I want to access "UserTutorialLocalService" in the template(Web content), In liferay 6.2 it is working fine based on this approach (http://liferaytrends.blogspot.in/2012/05/access-liferay-service-util-and-custom.html), not sure how to do in DXP.
So far I tried
It gives me below error.
Any help will be great.
We have developed one module based liferay service, having my custom table defined in service.xml(UserTutorial),
user-tutorial
--> user-tutorial-api
-->user-tutorial-service
Everything is fine so far.
Now I want to access "UserTutorialLocalService" in the template(Web content), In liferay 6.2 it is working fine based on this approach (http://liferaytrends.blogspot.in/2012/05/access-liferay-service-util-and-custom.html), not sure how to do in DXP.
So far I tried
<#assign tutorialService = serviceLocator.findService("user-tutorial","com.cac.usertutorial.service.TutorialLocalService") />
${tutorialService}
It gives me below error.
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator is not set for servlet context user-tutorial
at com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(PortletBeanLocatorUtil.java:46)
at com.liferay.portal.template.ServiceLocator.findService(ServiceLocator.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1458)
at freemarker.ext.beans.ReflectionCallableMemberDescriptor.invokeMethod(ReflectionCallableMemberDescriptor.java:52)
at freemarker.ext.beans.MemberAndArguments.invokeMethod(MemberAndArguments.java:48)
at freemarker.ext.beans.OverloadedMethodsModel.exec(OverloadedMethodsModel.java:62)
at freemarker.core.MethodCall._eval(MethodCall.java:62)
at freemarker.core.Expression.eval(Expression.java:78)
at freemarker.core.Assignment.accept(Assignment.java:131)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.Environment.process(Environment.java:302)
at freemarker.template.Template.process(Template.java:325)
at com.liferay.portal.template.freemarker.internal.FreeMarkerTemplate.processTemplate(FreeMarkerTemplate.java:135)
at com.liferay.portal.template.AbstractSingleResourceTemplate.doProcessTemplate(AbstractSingleResourceTemplate.java:67)
at com.liferay.portal.template.AbstractTemplate.write(AbstractTemplate.java:175)
at com.liferay.portal.template.AbstractSingleResourceTemplate.processTemplate(AbstractSingleResourceTemplate.java:90)
at com.liferay.portal.template.RestrictedTemplate.processTemplate(RestrictedTemplate.java:97)
at com.liferay.journal.transformer.JournalTransformer.mergeTemplate(JournalTransformer.java:669)
at com.liferay.journal.transformer.JournalTransformer.doTransform(JournalTransformer.java:340)
at com.liferay.journal.transformer.JournalTransformer.transform(JournalTransformer.java:118)
at com.liferay.journal.util.impl.JournalUtil.transform(JournalUtil.java:1177)
at com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.getArticleDisplay(JournalArticleLocalServiceImpl.java:7262)
at com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.getArticleDisplay(JournalArticleLocalServiceImpl.java:2142)
at sun.reflect.GeneratedMethodAccessor1020.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:163)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:54)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:58)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:169)
at com.sun.proxy.$Proxy474.getArticleDisplay(Unknown Source)
at com.liferay.journal.util.impl.JournalContentImpl.getArticleDisplay(JournalContentImpl.java:359)
at com.liferay.journal.util.impl.JournalContentImpl.getDisplay(JournalContentImpl.java:223)
at com.liferay.journal.content.web.internal.portlet.JournalContentPortlet.doView(JournalContentPortlet.java:125)
at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:301)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:497)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:262)
Any help will be great.
Thanks. I am able to fix it.
Hi Amit Doshi, I have the same issue. Could you please give a solution like how you solved your problem.
Thanks.
You can use following code to get the service inside FTL
<#assign myService = serviceLocator.findService("com.liferay.service.MyService")>
Let me know the exception you are getting, before putting above, you
have to make sure ServiceLocator is enabled from System
Settings.