Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Creating JournalFolder from UpdateArticleMVCActionCommand.
Hi Team,I have a requirement to create JournalFolder while creating content of a particular structure. For that, I have Customized UpdateArticleMVCActionCommand and creating JournalFolder using the below code.
ServiceContext serviceContext = ServiceContextFactory.getInstance(JournalFolder.class.getName(), actionRequest);
JournalFolder folder = JournalFolderLocalServiceUtil.addFolder(themeDisplay.getUserId(), groupId,
parentFolderId, folderName, folderDescription,
serviceContext);
Below are logs that I am getting while creating a content.Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:540)
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:562)
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:553)
at com.liferay.journal.model.impl.JournalFolderModelImpl.setExpandoBridgeAttributes(JournalFolderModelImpl.java:1062)
at com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.addFolder(JournalFolderLocalServiceImpl.java:116)
ServiceContext serviceContext = ServiceContextFactory.getInstance(JournalFolder.class.getName(), actionRequest);
JournalFolder folder = JournalFolderLocalServiceUtil.addFolder(themeDisplay.getUserId(), groupId,
parentFolderId, folderName, folderDescription,
serviceContext);
Below are logs that I am getting while creating a content.Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:540)
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:562)
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.setAttributes(ExpandoBridgeImpl.java:553)
at com.liferay.journal.model.impl.JournalFolderModelImpl.setExpandoBridgeAttributes(JournalFolderModelImpl.java:1062)
at com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.addFolder(JournalFolderLocalServiceImpl.java:116)
Attachments:
Could you check the expando attributes in the serviceContext?
serviceContext.getExpandoBridgeAttributes() returns a map.
I believe it tries to set an attribute that does exist for JournalArticle but that doesn't exist for folder.
Instead of using ServiceContextFactory.getInstance, I would simply create a new ServiceContext object and use that one. If you need to transport information, I would copy it from the JournalArticle serviceContext (e.g. if you want the folder to have the same permissions as the article).
serviceContext.getExpandoBridgeAttributes() returns a map.
I believe it tries to set an attribute that does exist for JournalArticle but that doesn't exist for folder.
Instead of using ServiceContextFactory.getInstance, I would simply create a new ServiceContext object and use that one. If you need to transport information, I would copy it from the JournalArticle serviceContext (e.g. if you want the folder to have the same permissions as the article).
Hi Christoph Rabel,I have tried passing the JournalArticle's ServiceContext as well as the new ServiceContext object but it did not help. This code was running in 6.2 but throwing error after migrating to 7.2
When you do:
ServiceContext serviceContext = new ServiceContext();
JournalFolder folder = JournalFolderLocalServiceUtil.addFolder(themeDisplay.getUserId(), groupId,
parentFolderId, folderName, folderDescription,
serviceContext);
The same exception still happens? That surprises me.
ServiceContext serviceContext = new ServiceContext();
JournalFolder folder = JournalFolderLocalServiceUtil.addFolder(themeDisplay.getUserId(), groupId,
parentFolderId, folderName, folderDescription,
serviceContext);
The same exception still happens? That surprises me.
Yes, it's happening. I have tried all possible ways to create ServiceContext object.
Please check serviceContext.getExpandoBridgeAttributes().
It returns a map. Please check the content. If this map is null or empty, nothing should happen. It simply can't throw because the relevant line is never reached. So, the map has to contain something. If you create a fresh serviceContext, the map should be empty.
It returns a map. Please check the content. If this map is null or empty, nothing should happen. It simply can't throw because the relevant line is never reached. So, the map has to contain something. If you create a fresh serviceContext, the map should be empty.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™