liferaystructureportletweb-content

Get a Web-content article with a specific Structure in Liferay


I have started developing portlets with Liferay and I would like to show one (or more) Web-content article(s) with a specified structure.

For example, suppose I've a structure "A" so how can I get the last web-content article which is created using this structure?

This article explains how to get articles with a tag but not with a structure.

Thank you


Solution

  • The Liferay API Docs (this is for 6.1, as I don't know what version you're using) are your friend as is the Liferay source code.

    In short you'll want to use one of the following API methods:

    JournalArticleLocalServiceUtil.getStructureArticles(long groupId, String structureId);
    JournalArticleLocalServiceUtil.getStructureArticles(long groupId, String structureId, int start, int end, OrderByComparator obc) 
    

    These rely on knowing the ID of the structure from which your content was generated, if you don't know what it is then you can use the following API method to get a list of all of them for your current Community:

    JournalStructureLocalServiceUtil.getStructures(long groupId) 
    

    You can also use similar methods to find Journal Articles by the JournalTemplate that they use:

    JournalTemplateLocalServiceUtil.getStructureTemplates(long groupId, String structureId); 
    
    JournalArticleLocalServiceUtil.getTemplateArticles(long groupId, String templateId);
    JournalArticleLocalServiceUtil.getTemplateArticles(long groupId, String templateId, int start, int end, OrderByComparator obc) 
    

    Comment back if you have any questions, or if this answers your question please hit the "Accept answer" button tick! Thanks!