Message Boards

Display entry from mysql database

Reiner Zufall, modified 2 Years ago.

Display entry from mysql database

New Member Posts: 22 Join Date: 7/6/20 Recent Posts

Hello there
​​​​​​​we have a requirement to display entrys in liferay searchcontainer which is written directly into the database, not using liferays actionrequest. this entry will only show up, when an actionrequest is triggered. Is there a way to display an entry which is written directly to mysql an then will show up directly in Liferays searchcontainer?

 

thumbnail
Russell Bohl, modified 2 Years ago.

RE: Display entry from mysql database

Expert Posts: 289 Join Date: 2/13/13 Recent Posts
<liferay-ui:search-container-results
    results="<%= JournalArticleLocalServiceUtil.getArticles(groupId, articleId, searchContainer.getStart(), searchContainer.getEnd(), new ArticleVersionComparator()) %>"
/>

I may be misunderstanding. You can fetch Liferay entities into a search container by calling their services, just like the above snippet demonstrates. Your own custom entities acan be fetched in the same way if you used Service Builder.

 

Reiner Zufall, modified 2 Years ago.

RE: RE: Display entry from mysql database

New Member Posts: 22 Join Date: 7/6/20 Recent Posts

Thank you for your answer,

Sry my english is bad.

No not this, i mean something other like this: https://liferay.dev/ask/questions/development/re-data-imported-directly-to-the-mysql-db-don-t-show-up-on-liferay-7

is there a way to do this in liferay 7.2.1?

thumbnail
Russell Bohl, modified 2 Years ago.

RE: RE: Display entry from mysql database

Expert Posts: 289 Join Date: 2/13/13 Recent Posts

Hi Reiner, I understand a bit better now, skimming that old thread. I guess when you say "written directly into the database, not using liferays actionrequest" you also mean that you're not using Liferay's services. Liferay entities should really be written to the DB only using the services. But, can you clarify a few things (see below):

Are we talking about a Liferay entity or a custom entity? Are you importing Users like the OP of the linked thread?

If a custom entitty, is it a Service Builder entity?

If it's a Liferay entity, are you writing an app with search container code to display the entities, or are you trying to see the imported objects in the native Liferay UI?

Reiner Zufall, modified 2 Years ago.

RE: RE: Display entry from mysql database

New Member Posts: 22 Join Date: 7/6/20 Recent Posts

Hi Russell

thank your for your answer,

we use two ways to write values into the database. The first is liferay with its servicebuilder and the second is another software, which writes directly into the same database table, but the software does not use any of the liferay services.

What we want is, when the other software writes directly into the database, liferay only display this entity. It works, but only when pressing a button, which executes a action request to refresh the database tables.

is there a way, where liferay recognize changes into the database and refresh it without pressing a button.

 

thumbnail
Russell Bohl, modified 2 Years ago.

RE: RE: Display entry from mysql database

Expert Posts: 289 Join Date: 2/13/13 Recent Posts

Hi Reiner, I still don't know if I have enough understanding of the situation, but I'm closer now. I'm going to tell you what I think I know about your situation, and you can correct anything that is wrong.

 

  • You are working with a service builder entity that you developed, not one of Liferay's entities.
  • In addition to a portlet that calls your service builder services, there's another tool that adds entities to the database.
  • Your service builder backed portlet works as expected: when you add an entity through the portlet, the render phase is called after the entity is added, so the new entity displays properly in the portlet's search container.
  • However, when the other tool adds entities to the database, the render phase is not invoked, so the new entities are not reflected in the search container.
  • If you refresh the page, the render phase is invoked, the entity list is re-fetched form the DB, and all the entities show up as expected.
  • Your question then is about how you can avoid refreshing the page to display the new entities.

If that's all accurate, I'm afraid I am at a loss. One idea that may or may not work would be to 

1. Create a model listener for your model, probably listening via the onAfterCreate method, but see the javadoc for BaseModelListener for a list of the events. See the Creating a Model Listener article to quickly get up and running with a Model Listener.

2. In the ModelListener, invoke the render method of the portlet. I don't know if this will work or not.
 

thumbnail
Olaf Kock, modified 2 Years ago.

RE: Display entry from mysql database

Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent Posts

Given the other article you linked and your original question:

  • If there's any overlap with Liferay's entities (e.g. through primary keys generated by CounterLocalService), you'll need to cater for this and reserve a certain number of keys. Otherwise yes, you'll get duplicate keys and mess up your database
  • an ActionRequest has nothing to do with any database data. Please specify (preferably with simplified code, or database snippets, what your situation is on the database side and how you actually enter data (so far you only tell us how you don't enter data, which is not useful)
  • Liferay's SearchContainer is best used with Liferay Entities (but probably can be used with other entities as well), so you'll need to really be sure you're generating the ids of the entities in a proper way that can be interpreted by the portal.