Forums de discussion

Issue with AddArticle in liferay 7

thumbnail
devaraj s, modifié il y a 7 années.

Issue with AddArticle in liferay 7

Regular Member Publications: 228 Date d'inscription: 21/05/12 Publications récentes
Hi Team,
We are using Liferay 7 GA3 CE, i want to save web content by my custom portlet by using structure and template,
1) To Show the form on front end i am using following liferay html tag
 <liferay-ddm:html checkRequired="<%= true %>" classNameId="<%= PortalUtil.getClassNameId(DDMStructure.class) %>" classPK="<%=structureId%>" fields="<%= newFields %>" fieldsNamespace="attStrFrm" repeatable="<%= true %>" /> 


2) To handle the values of field i am using following Liferay APIs
ServiceContext serviceContext =  ServiceContextFactory.getInstance(JournalArticle.class.getName(), uploadPortletRequest); 
DDMFormValues ddmFormValues = DDMUtil.getDDMFormValues(ddmStructure.getStructureId(), (String)uploadPortletRequest.getAttribute("fieldsNamespace"), serviceContext);
Fields fields = DDMUtil.getFields(ddmStructure.getStructureId(), ddmFormValues); 
String content = _journalConverter.getContent(ddmStructure, fields) 
journalArticle = JournalArticleServiceUtil.addArticle(groupId, 0L, 0L, 0L, "", true, titleMap,
						descriptionMap, content, structureKey, templateKey, null, now.get(2), now.get(5), now.get(1),
						now.get(11), now.get(12), 0, 0, 0, 0, 0, true, now.get(2), now.get(5), now.get(1), now.get(11),
						now.get(12), true, true, false, null, null, images, title, serviceContext); 


3)Articles has been created but with blank values, and following exception occurring due to blank value of variable used in template(.freemarker).
ERROR [http-nio-8080-exec-9][runtime:60] Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==&gt; title  [in template "20116#20160#32398" at line 1, column 10]

----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use &lt;#if myOptionalVar??&gt;when-present&lt;#else&gt;when-missing<!--#if-->. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----

----
FTL stack trace ("~" means nesting-related):
       - Failed at: #if title.getData()??  [in template "20116#20160#32398" at line 1, column 5]
----

Java stack trace (for programmers):
----
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
       at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:131)
       at freemarker.core.UnexpectedTypeException.newDesciptionBuilder(UnexpectedTypeException.java:77)
       at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:40)
       at freemarker.core.NonHashException.<init>(NonHashException.java:46)
       at freemarker.core.Dot._eval(Dot.java:45)
       at freemarker.core.Expression.eval(Expression.java:78)
       at freemarker.core.MethodCall._eval(MethodCall.java:55)
       at freemarker.core.Expression.eval(Expression.java:78)
       at freemarker.core.ExistsExpression._eval(ExistsExpression.java:45)
       at freemarker.core.Expression.eval(Expression.java:78)
       ….
</init></init>


Could anyone please suggest , what is the root cause of this exception.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Issue with AddArticle in liferay 7

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
It's telling you title is null or empty, but you don't share what titleMap is or how it is populated. Given the error, it kind of points at titleMap as the issue.








Come meet me at the LSNA!
thumbnail
devaraj s, modifié il y a 7 années.

RE: Issue with AddArticle in liferay 7

Regular Member Publications: 228 Date d'inscription: 21/05/12 Publications récentes
I have structure with two fields, title(text field) and description(text area). And following freemarker code i have used in template.
<h1>&lt;#if title.getData()??&gt;${title.getData()}&lt;#else&gt;Not Title Available<!--#if--></h1>
<p>&lt;#if description.getData()??&gt;${description.getData()}&lt;#else&gt;No Description Available<!--#if--></p>


For fetching the content from request object,I am using following code , in controller I am able to get all the content which is passed from UI.
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
ServiceContext serviceContext =  ServiceContextFactory.getInstance(JournalArticle.class.getName(), uploadPortletRequest);
DDMFormValues ddmFormValues = DDMUtil.getDDMFormValues(ddmStructure.getStructureId(), (String)uploadPortletRequest.getAttribute("fieldsNamespace"), serviceContext);
Fields fields = DDMUtil.getFields(ddmStructure.getStructureId(), ddmFormValues);
String content = _journalConverter.getContent(ddmStructure, fields)


We tried to debug the content value which is generated from _journalConverter.getContent(ddmStructure, fields) method, Conent value supposed to be like
<!--?xml version="1.0"?-->

<root available-locales="en_US" default-locale="en_US">
                <dynamic-element name="Title" type="text" index-type="keyword" instance-id="itld">
                                <dynamic-content language-id="en_US">Chirstmas Leave</dynamic-content>
                </dynamic-element>
                <dynamic-element name="Description" type="text_box" index-type="keyword" instance-id="qayv">
                                <dynamic-content language-id="en_US">Office will be closed for one week on occasion of Chistmas.</dynamic-content>
                </dynamic-element>
</root>


but the value returned by the getcontent method like below.
<!--?xml version="1.0"?-->
<root available-locales="en_US" default-locale="en_US">
</root>


Could any one help us to understand how can we fetch both field data from request object and convert into xml format required by liferay.
The code we are using to fetch xml formatted content from request object. by liferay API we have copied from liferay 7.0GA3 source code, but its not working on Custom portlet. Is there any other option available to convert it to proper xml format.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Issue with AddArticle in liferay 7

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
The title being referred to is not a field in your structure, it's the title for the article you're using in the JournalArticleServiceUtil.addArticle() call.

Articles have titles too and they need to be correctly populated. Whatever you put into your structure is your business, but you are required to satisfy the Liferay API.






Come meet me at the LSNA!
thumbnail
devaraj s, modifié il y a 7 années.

RE: Issue with AddArticle in liferay 7

Regular Member Publications: 228 Date d'inscription: 21/05/12 Publications récentes
Thanks for the information, we will try this.