userid = <acquire some userid>
groupid = <acquire relevant site's groupid>
cnameid = PortalUtil.getClassNameId(JournalArticle.class)
context = new ServiceContext()
AssetDisplayPageEntryLocalServiceUtil.addAssetDisplayPageEntry(userid, groupid, cnameid, article.getResourcePrimKey(), AssetDisplayPageConstants.TYPE_SPECIFIC, context)
</acquire></acquire>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
RE: Programmatically asign Display Page to JournalArticle
I'm creating an interface to create JournalArticles with a custom (global) structure. I can't set a default display page for this structure, as it's site dependant.
Trying to figure out how I can set the display page.
I noticed JournalArticle's .getLayout() (on an article with the display page set correctly) seems to represent it (partially at least), but setLayoutUuid() + persist() don't seem to have any effect (at all).
Ideally I'm looking for a method to set a JournalArticle's display page from an url (e.g. a custom setDisplayPage(JournalArticle j, String url) method), though just getting the display page from another - correctly configured - JournalArticle and going from there would be perfectly workable as well (e.g. setDisplayPage(JournalArticle correctly_configured_article, JournalArticle new_article) )
I'm assuming the class AssetDisplayPageEntry will have to be used, but despite all my digging I can't figure it out. Just some pointers in the right direction should be fine, though code snippets are always welcome :-)
thanks in advance!
Solution:
Adding the correct Layout to the JournalArticle isn't enough.
an AssetDisplayPageEntry needs to be created as well:
Trying to figure out how I can set the display page.
I noticed JournalArticle's .getLayout() (on an article with the display page set correctly) seems to represent it (partially at least), but setLayoutUuid() + persist() don't seem to have any effect (at all).
Ideally I'm looking for a method to set a JournalArticle's display page from an url (e.g. a custom setDisplayPage(JournalArticle j, String url) method), though just getting the display page from another - correctly configured - JournalArticle and going from there would be perfectly workable as well (e.g. setDisplayPage(JournalArticle correctly_configured_article, JournalArticle new_article) )
I'm assuming the class AssetDisplayPageEntry will have to be used, but despite all my digging I can't figure it out. Just some pointers in the right direction should be fine, though code snippets are always welcome :-)
thanks in advance!
Solution:
Adding the correct Layout to the JournalArticle isn't enough.
an AssetDisplayPageEntry needs to be created as well:
JournalArticle article =
Not sure if this helps, but in the Porygon theme we set a default Display Page for a ddm structure. Maybe that can give you some hints.
Look at _addDisplayPageEntry in the PorygonSiteInitializer
Look at _addDisplayPageEntry in the PorygonSiteInitializer
LayoutPageTemplateEntry seems specific for Fragment based display pages (I'm using a regular page with default asset publisher); I'll have a look though, might give some new clues, thanks
Got it, maybe I didn't fully understand. Another more classic approach can be found in the PorygonSiteInitializer. Just in case that provides any clues.
That did it, thanks!
I am not sure which version you use, but at least in 7.0 you can set the layoutUuid to the page uuid.
Basically you would write something like (pseudocode)
Layout layout = layoutlocalservice.getLayout(...);
String uuid = layout.getLayoutUUID();
journalarticle.setLayoutUuid(uuid);
journalarticle.persist();
Basically you would write something like (pseudocode)
Layout layout = layoutlocalservice.getLayout(...);
String uuid = layout.getLayoutUUID();
journalarticle.setLayoutUuid(uuid);
journalarticle.persist();
Tried this already and doesn't seem to have any effect:
(excuse the messy code, just throwing stuff at the groovy tab)
results in
Which is the "page" i want (/nieuwsbericht, with default-asset-publisher etc set). No result however:

Unrelated: tried JournalArticleLocalServiceUtil.updateJournalArticle(jul) as well, It won't run however, because jul is of type 'JournalArticleImpl'.. confusing
(excuse the messy code, just throwing stuff at the groovy tab)
locale = LocaleUtil.getSiteDefault()
group = GroupLocalServiceUtil.search(PortalUtil.getDefaultCompanyId(), null, "Liferay DXP", null, null, false, 0, 1).get(0);
items =JournalArticleLocalServiceUtil.getStructureArticles(group.getGroupId(),"NIEUWS")
item =items.get(5) // <-- article with display page set
jul = items.get(35) // <-- article with display page not set
lay = item.getLayout()
jul.setLayoutUuid(lay.getUuid())
jul.persist()
results in
Title: Jobevent IT op komst
getLayout():
{mvccVersion=29, uuid=638086dc-28b2-bbd2-8834-01273b98d44e, plid=118492, groupId=20126, companyId=20099, userId=37820, userName=Tom Aerts,
createDate=Fri Jan 04 09:12:38 GMT 2019, modifiedDate=Tue Mar 12 15:39:33 GMT 2019, privateLayout=false, layoutId=22, parentLayoutId=1,
name=NieuwsBericht, title=, description=, keywords=, robots=, type=portlet, typeSettings=CUSTOMIZABLE_LAYOUT=false
addToAutoMenus=on
column-1=com_liferay_asset_publisher_web_portlet_AssetPublisherPortlet_INSTANCE_BATVWdSe2Vrv,com_liferay_asset_publisher_web_portlet_RelatedAssetsPortlet_INSTANCE_TO6uXDgeDSTz
column-1-customizable=false
column-2=wieiswieportlet_INSTANCE_KvFn2ihDhNXf,menuportlet_INSTANCE_TawcY5OvKGn4,delijn_INSTANCE_1b1UECnPLrLY
column-2-customizable=false
default-asset-publisher-portlet-id=com_liferay_asset_publisher_web_portlet_AssetPublisherPortlet_INSTANCE_BATVWdSe2Vrv
layout-template-id=2_columns_iii
layoutUpdateable=true
sitemap-changefreq=daily
sitemap-include=1
, hidden=false, friendlyURL=/nieuwsbericht, iconImageId=0, themeId=classic_WAR_classictheme, colorSchemeId=, css=, priority=1,
layoutPrototypeUuid=, layoutPrototypeLinkEnabled=false, sourcePrototypeLayoutUuid=, lastPublishDate=null}Which is the "page" i want (/nieuwsbericht, with default-asset-publisher etc set). No result however:

Unrelated: tried JournalArticleLocalServiceUtil.updateJournalArticle(jul) as well, It won't run however, because jul is of type 'JournalArticleImpl'.. confusing
I think, the answer of Chema is correct, I checked the sourcecode of the JournalPortlet, see _updateAssetDisplayPage:
https://github.com/liferay/liferay-portal/blob/7.2.x/modules/apps/journal/journal-web/src/main/java/com/liferay/journal/web/internal/portlet/JournalPortlet.java
Btw.: Good to know that this has changed. I think we did something similar as you do. JournalArticleLocalServiceWrapper + "fix" the displaypage for news entries. And some day in the future, we will migrate that to 7.2 or so ...
https://github.com/liferay/liferay-portal/blob/7.2.x/modules/apps/journal/journal-web/src/main/java/com/liferay/journal/web/internal/portlet/JournalPortlet.java
Btw.: Good to know that this has changed. I think we did something similar as you do. JournalArticleLocalServiceWrapper + "fix" the displaypage for news entries. And some day in the future, we will migrate that to 7.2 or so ...