Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 6.1.0 CE RC1, 6.1.0 CE GA1, 6.2.0 CE M2
-
Fix Version/s: 6.1.1 CE GA2, 6.1.20 EE GA2, 6.2.0 CE M2
-
Component/s: WCM, WCM > Asset Publisher, WCM > Web Content Administration
-
Labels:
-
Branch Version/s:6.1.x
-
Backported to Branch:Committed
-
Fix Priority:5
-
Similar Issues:
Description
Description:
Using the AssetRenderer to display Journal/Web Content in a custom portlet results in a null pointer when the Web Content has an associated Template.
This is because the template parser com.liferay.portal.kernel.templateparser.BaseTransformer attempts to lookup the Template Parser with the following code:
Line 147 of BaseTransformer.java
templateParser =(TemplateParser)InstanceFactory.newInstance(templateParserClassName);
This results in the InstanceFactory getting the class loader from the current thread:
Line 47 of InstanceFactory.java
Thread currentThread = Thread.currentThread();
The class loader for the current thread will be the class loader for the custom portlet, thus the expected classes will not be available and an exception:
com.liferay.portal.kernel.templateparser.TransformException:
java.lang.ClassNotFoundException: com.liferay.portlet.journal.util.VelocityTemplateParser
will be generated.
Fortunately the InstanceFactory.newInstance(..) call can be passed a class loader, so modification of
Line 147 of BaseTransformer.java to:
templateParser=(TemplateParser)InstanceFactory.newInstance(
PortalClassLoaderUtil.getClassLoader(),
templateParserClassName);
i.e. passing in the PortalClassLoader fixes the issue.
Step to reproduce:
1. Create a structure and template for web content.
2. Add an instance of web content using the new structure and template.
3. Write a custom portlet that attempt to display the data using the AssetRenderer in FULL, i.e. AssetRenderer.TEMPLATE_FULL_CONTENT
example code:
<%
AssetRendererFactory af = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName( JournalArticle.class.getName());
AssetRenderer assetRenderer=af.getAssetRenderer('articleId');
String renderPath=assetRenderer.render(portletRequest, portletResponse, AssetRenderer.TEMPLATE_FULL_CONTENT);
String renderPortletId = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName( JournalArticle.class.getName()).getPortletId()
<liferay-util:include page="<%=renderPath%>" portletId="<%=renderPortletId %>" />
4. View custom portlet (sometimes it will work on the first view)
5. Refresh page - null pointer will occur in "html\portlet\journal\asset\full_content.jsp" at line 43 as the articleDisplay object is null due to the above exception.
Issue Links
- is duplicated by
-
LPS-25992
It is not possible to display structured web-content in third-party portlet.
-

This issue is a pretty big deal; it actually affects any call to JournalContentUtil (e.g. even getDisplay )
It prevents developers from programatically retrieving any content.