I have a theme project in liferay. I have created a new table called colors in my liferay MySQL database. The colors table is given below
Actually I have a requirement that a particular css file should be loaded in theme based on the color table value whose status is true and my velocity template should be somewhat like as shown below
#set ($myColorService = $serviceLocator.findService("com.colors.themes.service.ColorLocalService"))
#set ($myColor = $myColorService.fetchActiveColor())
#if ($myColor == "blue")
<link href="$css_folder/themes/blue.css" rel="stylesheet" type="text/css"/>
#elseif ($myColor == "orange")
<link href="$css_folder/themes/orange.css" rel="stylesheet" type="text/css"/>
#else
<link href="$css_folder/themes/green.css" rel="stylesheet" type="text/css"/>
The following things are somethings which I have done so far
I have created a service builder project (theme_service-portlet) for the colors table. The service.xml is shown below
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd"> <service-builder package-path="com.colors.themes"> <author>user</author> <namespace>theme</namespace> <entity name="Colors" local-service="true" remote-service="true"> <column name="colorId" type="long" primary="true" /> <column name="colorName" type="String" /> <column name="status" type="boolean" /> <finder return-type="Collection" name="Colors"> <finder-column name="status" /> </finder> </entity> </service-builder>
Builded the service and jar (
theme_service-portlet-service.jar
) is generated under lib folder.- Copy the
theme_service-portlet-service.jar
and placed underliferay-portal-6.2-ce-ga2\tomcat-7.0.42\lib\ext
folder. - In
portal_normal.vm
I have used the following code:
#set ($myColorService = $serviceLocator.findService("com.colors.themes.service.ColorLocalService")) #set ($myColor = $myColorService.fetchActiveColor()) #if ($myColor == "blue") <link href="$css_folder/themes/blue.css" rel="stylesheet" type="text/css"/> #elseif ($myColor == "orange") <link href="$css_folder/themes/orange.css" rel="stylesheet" type="text/css"/> #else <link href="$css_folder/themes/green.css" rel="stylesheet" type="text/css"/>
- Restarted the tomcat server
But I am getting the following exception
04:44:55,896 ERROR [http-bio-8080-exec-3][ServiceLocator:39] com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.colors.themes.service.ColorLocalService' is defined
com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.colors.themes.service.ColorLocalService' is defined
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:122)
at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:98)
at com.liferay.portal.template.ServiceLocator.findService(ServiceLocator.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
at org.apache.velocity.Template.merge(Template.java:328)
Can anyone please tell me some solution for this