Message Boards

Can't get a category property at FTL

Karmel Idarraga, modified 2 Years ago.

Can't get a category property at FTL

New Member Post: 1 Join Date: 10/28/21 Recent Posts

Hi all!! 

I have an Freemarker category navigation template which needs no get a category custom property. My code was working until er hace upgrade from Liferay 7.3 CE GA6 to Liferay 7.3 GA8.

Now we are getting the following error:

com.sun.proxy.$Proxy1796 cannot be cast to com.liferay.asset.category.property.model.AssetCategoryProperty.

At GA6 we have the following ftl working:

<#assign assetCategory = serviceLocator.findService("com.liferay.asset.category.property.service.impl.AssetCategoryPropertyLocalServiceImpl")>
<#assign assetCategoryNuevo = serviceLocator.findService("com.liferay.portlet.asset.service.impl.AssetCategoryPropertyServiceImpl")>
<#assign images_folder = themeDisplay.getPathThemeImages()>
<#if entries?has_content>
<div class="container my-5">
    <h2 class="mb-5"><@liferay.language key="DOG-ADT-catalogo-opendata-header"/></h2>
	<#list entries as curVocabulary>
	    <#assign categories = curVocabulary.getCategories() />
	    <#if categories?has_content>
	        <@displayCategories categories=categories />
	    </#if>
	</#list>
	</div>
</#if>

<#macro displayCategories
	categories
>
	<#if categories?has_content>
	    <div class="row">
			<#list categories as category>
                <#assign key = category.getCategoryId()>
                <#assign valorPropiedad = assetCategoryNuevo.getCategoryProperty(key,"image")>
                <a href="${categoryURL}${key}" class="ficha-categoria"> 
                    <img src="${images_folder}/opendata/${valorPropiedad.getValue()}" >
                    <p>${category.getTitle(locale)}</p>
                </a>
			</#list>
		</div>	
	</#if>
</#macro>

When the upgrade was done, we get an error because the service was removed (or changed the location), so we changed it to use the following:

<#assign assetCategoryKernel = serviceLocator.findService("com.liferay.asset.kernel.service.AssetCategoryPropertyLocalService")>

But now we are getting the following error:

Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy1796 cannot be cast to com.liferay.asset.category.property.model.AssetCategoryProperty
    at com.liferay.portal.template.freemarker.internal.RestrictedLiferayObjectWrapper.wrap(RestrictedLiferayObjectWrapper.java:229)
    at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1509)
    at freemarker.ext.beans.ReflectionCallableMemberDescriptor.invokeMethod(ReflectionCallableMemberDescriptor.java:56)
    at freemarker.ext.beans.MemberAndArguments.invokeMethod(MemberAndArguments.java:51)
    at freemarker.ext.beans.OverloadedMethodsModel.exec(OverloadedMethodsModel.java:61)
    ... 278 more
 

 

Can anyone help us, please?

Thanks in advance

thumbnail
Mohammed Yasin, modified 2 Years ago.

RE: Can't get a category property at FTL

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

Hi ,

You can try using below code  for fetching the AssetCategoryProperty.

<#assign 					
	assetCategoryPropService = serviceLocator.findService("com.liferay.asset.category.property.service.AssetCategoryPropertyLocalService")
	catPropValue = assetCategoryPropService.getCategoryProperty(categoryId,"propertyName")
/>
${catPropValue.getValue()}