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
Liferay 7.2 - Can I inject my code on Liferay existing classes?
I want to add some data to my database when the user performs some actions. If a user deletes a page for example, I want to add a row with some information on my database. To do this I would like to add one or two lines of my code into the class/method that deletes the page to add that data to my database also.
I have already created the database and tried to add some rows in my table for tests purposes and is working. Now I would like to move this code to the class that process the deletion of the pages for example.
It is possible to inject code of mine in the classes that already exists? What would be the best approach to do this?
I have already created the database and tried to add some rows in my table for tests purposes and is working. Now I would like to move this code to the class that process the deletion of the pages for example.
It is possible to inject code of mine in the classes that already exists? What would be the best approach to do this?
You should consider using model listeners for this purpose. Then you don't have to override already existing code.
Matthew is right here, the model listener is the way to go. It is, in fact, the approach Liferay recommends for adding Audit tracking for adds, updates and deletes.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™