Foros de discusión
LocaleTransformerListener - Unable to filter by localizability (NPE)
Ketan Solanki, modificado hace 6 años.
LocaleTransformerListener - Unable to filter by localizability (NPE)
Junior Member Mensajes: 63 Fecha de incorporación: 28/05/14 Mensajes recientes
Hi,
I have written program to add/update structure/template and the same for journal article aka web content. I have been able to successfully implement all 3 components programatically, so when I add a new web content it is added to Liferay and I can show those web content successfully on the page too!
However on the Liferay console, I get an NPE error as following (full stack trace is attached)
I checked the concerned method which is as following, and my suspect is that NPE might be occurring at String languageId = dynamicContentElement.attributeValue("language-id"); line, I tried to debug the code but somehow my Liferay's jar files and source code in IDEA are not in sync and couldn't debug properly. I tried to check the Liferay's version of jar but I am not sure where to check that.
This aside, when I add a new web content from the UI for the same structure/template, I don't get that error! Meaning, the problem is only in the web content (journal article) addition through my custom program. I tried to compare the content of the UI added web content and program added web content, they were same as well - except that I am not passing instance-id in the program web content. I also tried to pass the language-id field in my content but that didn't solve the problem.
I am not sure from where/why is this NPE is occurring. If you have any idea then please let me know.
P.S. I have added an attachment - createWebContent.txt - which contains the method I am using to add a new journal article - pls check if something is wrong here!
Thanks & Regards,
Ketan
I have written program to add/update structure/template and the same for journal article aka web content. I have been able to successfully implement all 3 components programatically, so when I add a new web content it is added to Liferay and I can show those web content successfully on the page too!
However on the Liferay console, I get an NPE error as following (full stack trace is attached)
23:15:53,026 ERROR [http-nio-8080-exec-7][LocaleTransformerListener:193] Unable to filter by localizability
java.lang.NullPointerException
at com.liferay.journal.transformer.LocaleTransformerListener.filter(LocaleTransformerListener.java:92)
at com.liferay.journal.transformer.LocaleTransformerListener.filterByLocalizability(LocaleTransformerListener.java:212)
at com.liferay.journal.transformer.LocaleTransformerListener.filterByLocalizability(LocaleTransformerListener.java:189)
at com.liferay.journal.transformer.LocaleTransformerListener.onXml(LocaleTransformerListener.java:70)
at com.liferay.journal.transformer.JournalTransformer.doTransform(JournalTransformer.java:187)
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:7012)
at com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.getArticleDisplay(JournalArticleLocalServiceImpl.java:2012)
at sun.reflect.GeneratedMethodAccessor1605.invoke(Unknown Source)
I checked the concerned method which is as following, and my suspect is that NPE might be occurring at String languageId = dynamicContentElement.attributeValue("language-id"); line, I tried to debug the code but somehow my Liferay's jar files and source code in IDEA are not in sync and couldn't debug properly. I tried to check the Liferay's version of jar but I am not sure where to check that.
protected void filter(Element dynamicElementElement, DDMStructure ddmStructure, String name, String defaultLanguageId)
throws PortalException {
boolean localizable = GetterUtil.getBoolean(ddmStructure.getFieldProperty(name, "localizable"));
List<element> dynamicContentElements = dynamicElementElement.elements("dynamic-content");
for (Element dynamicContentElement : dynamicContentElements) {
String languageId = dynamicContentElement.attributeValue("language-id");
if (!localizable && !languageId.equals(defaultLanguageId)) {
dynamicElementElement.remove(dynamicContentElement);
}
}
}</element>
This aside, when I add a new web content from the UI for the same structure/template, I don't get that error! Meaning, the problem is only in the web content (journal article) addition through my custom program. I tried to compare the content of the UI added web content and program added web content, they were same as well - except that I am not passing instance-id in the program web content. I also tried to pass the language-id field in my content but that didn't solve the problem.
I am not sure from where/why is this NPE is occurring. If you have any idea then please let me know.
P.S. I have added an attachment - createWebContent.txt - which contains the method I am using to add a new journal article - pls check if something is wrong here!
Thanks & Regards,
Ketan
Archivos adjuntos:
Jorge Díaz, modificado hace 6 años.
RE: LocaleTransformerListener - Unable to filter by localizability (NPE) (Respuesta)
Liferay Master Mensajes: 753 Fecha de incorporación: 9/01/14 Mensajes recientes
I had a quick look your error and your code and I think the issue is in the title or in the content that you are getting from WebContentInput object.
Try creating a webcontent from both Liferay interface and your program. Execute a SQL query to JournalArticle table and compare all fields. If there is any difference, you have to fix something in your code.
Try creating a webcontent from both Liferay interface and your program. Execute a SQL query to JournalArticle table and compare all fields. If there is any difference, you have to fix something in your code.
Ketan Solanki, modificado hace 6 años.
RE: LocaleTransformerListener - Unable to filter by localizability (NPE)
Junior Member Mensajes: 63 Fecha de incorporación: 28/05/14 Mensajes recientes
Hi Jorge,
Thanks very much for your time for going through the documents and my questions, and also providing me feedback.
Your feedback has actually worked...
Though I compared the content of UI added and program added earlier as I had mentioned, I didn't go via table data I had just relied on the object retrieved via program and printing it on the console and in this process I had missed following thing to compare!
In the input data, i.e. content I had
But I should have following
Thanks again Jorge.
For the benefits of others, I am attaching the xml file of the input data
Thanks very much for your time for going through the documents and my questions, and also providing me feedback.
Your feedback has actually worked...
Though I compared the content of UI added and program added earlier as I had mentioned, I didn't go via table data I had just relied on the object retrieved via program and printing it on the console and in this process I had missed following thing to compare!
In the input data, i.e. content I had
<dynamic-content>Car</dynamic-content>
But I should have following
<dynamic-content language-id="en_US">Car</dynamic-content>
the language-id was missing on dynamic-content. Earlier I had added language-id field on dynamic-element which was wrong-not required.Thanks again Jorge.
For the benefits of others, I am attaching the xml file of the input data
Archivos adjuntos: