I am new to Liferay and am working on a model writer for Web Content Articles (Journal Articles). It is important to keep the title and the content after the creation. I have written a simple script for this. However, the output title is empty and the content is zero.
The article object itself does not contain a key for title or content. Unfortunately, I don’t know what to do and hope that someone has already had experience with this.
package webcontenthandler;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.BaseModelListener;
import com.liferay.portal.kernel.model.ModelListener;
import org.osgi.service.component.annotations.Component;
import java.util.List;
@Component(
immediate = true,
service = ModelListener.class
)
public class WebContentHandler extends BaseModelListener<JournalArticle> {
@Override
public void onAfterCreate(JournalArticle article) {
try {
JournalArticle myarticle = JournalArticleLocalServiceUtil.getArticle(article.getGroupId(), article.getArticleId(), article.getVersion());
System.out.println("article: " + myarticle);
System.out.println("article content: " + myarticle.getContent());
System.out.println("article title: " + myarticle.getTitle());
System.out.println("article title: " + myarticle.getTitleCurrentValue());
} catch (PortalException e) {
throw new RuntimeException(e);
}
}
@Override
public Class<JournalArticle> getModelClass() {
return JournalArticle.class;
}
}