Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:06:17+00:00 2026-05-28T07:06:17+00:00

I trying to modify JournalArticle assets (need to set categories depending of article layout

  • 0

I trying to modify JournalArticle assets (need to set categories depending of article layout parents). I managed to implement ModelListener for JournalArticle. In method onAfterUpdate() I have JournalArticleLocalServiceUtil.updateAsset().

In logs everything is fine. I have needed category id in parameters, but it doesn’t appear in categories list in article when I open article editor in the next time.

Is it possible to save changes in model from ModelListener somehow or it’s just for monitoring and I can’t modify model from this listener?

Code (reduced version):

package mypackage;

// imports

public class JournalArticleListener implements ModelListener {

    private void updateCategories(JournalArticle article) {
        try {
            long[] categoriesArray = getCategories(article);  // this works fine
            String[] tagsArray = getTags(article); // this also works fine

            JournalArticleLocalServiceUtil.updateAsset(article.getUserId(), article, categoriesArray, tagsArray);
        } catch (PortalException ex) {
            // logger
        } catch (SystemException ex) {
            // logger
        }
    }

    @Override
    public void onBeforeUpdate(Object model) throws ModelListenerException {
        updateCategories((JournalArticle)model);
    }

    // other abstract method implemented without any code inside
}

in liferay-hook.xml I have

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.0.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_0_0.dtd">

<hook>
    <model-listener>
        <model-listener-class>mypackage.JournalArticleListener</model-listener-class>
        <model-name>com.liferay.portlet.journal.model.JournalArticle</model-name>
    </model-listener>
</hook>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:06:18+00:00Added an answer on May 28, 2026 at 7:06 am

    As far as I can tell, your code looks fine but I can think of a few things you could try. Please let me know if this worked for you.

    First. check to see if the article is approved. If the article is in the draft state the data won’t reflected until it is approved.

    Second. Instead of using a model listener try overwriting the service with the hook instead.

    <service>
        <service-type>com.liferay.portlet.journal.service.JournalArticleService</service-type>
        <service-impl>com.example.hook.service.impl.JournalArticleServiceImpl</service-impl>
    </service>
    

    You’ll need to implement its service wrapper, JournalArticleServiceWrapper.

    Overwrite the update methods (there could be several) and call its parent method then do your logic. Like so:

    public JournalArticle someUpdateArticleMethod(Many params) SomeExceptions {
        JournalArticle journalArticle = super.someUpdateArticleMethod(params);
    
        // my code here.
    }
    

    Doing it by model listeners is definitely easier. Though I’m not sure that this is the actual problem, it maybe that there is an issue using onAfterUpdate to update the model since an infinite loop could be created.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify some library and I need to store a float value
I'm trying to modify the vestal_versions plugin to accept a parameter I set upon
I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but
I'm trying to modify the class of an element if an ajax call based
I am trying to modify the output stream to search/replace some XHTML tags returned
I'm currently trying to modify some HttpWebRequest functions, but I can't do it through
I'm trying to modify the contents of an MSI file using Powershell. To do
I'm trying to modify the UI of a Redmine installation (Redmine 0.7.3.devel.2093 (MySQL)). When
Hi I'm trying to modify a web page so that it loads faster. Since
I am trying to modify the amcap, an application from Windows SDK's example to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.