简体   繁体   中英

Using staticUtil service in liferay web-content throwing freemarker error

I have to get ThemeDisplay() in web-content to compare page title. I am using <#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()> To get service context, but it's throwing freemarker exception mentioned below:

No error description was specified for this error; low-level message:
 java.lang.ClassNotFoundException: com.liferay.portal.kernel.service.ServiceContext cannot be found by com.liferay.portal.template.freemarker_2.0.29

----
FTL stack trace ("~" means nesting-related):
    - Failed at: #assign service = staticUtil["com.lif...  [in template "20155#20195#54243" at line 21, column 1]
----

FYI: I already enabled freemarker engine setting in control panel freemarker engine. Also in portal-ext.properties file.

I just tried in my freemarker template the following:

<#assign
serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext() />

and it works as of Liferay 7 GA5. Are you sure you have correctly enabled the Freemarker variable? To verify:

  • Click Menu -> Control Panel -> Configuration -> System Settings
  • Search for freemarker and hit enter
  • Click the three vertical dots -> Edit
  • Change staticUtil to something like nonExistent (just removing brought it back for me afaik).
  • Shut off your server and remove the setting from your portal-ext.properties file. It's not necessary.

How about now?

Thanks guys for your precious responses, I found that it's not working for me, because i am using embedded web-content. And in that case it's not working :)

Sorry for less explain in my question. Actually i didn't know that embedding web-content in theme is a different case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM