掲示板

ISSUE WITH MODEL LISTENER HOOK

11年前 に Rajashekar Katla によって更新されました。

ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi All,

I have developed portlets with my custom entities by using service builder and generated service classes. And in my entities I have user and organization id’s.

But I have requirement like whenever the user/organization is deleted from Liferay user_ & organization_ tables, I need to delete those corresponding user/organization from my tables.
For that I created two hooks to act as listener for those tables.
1) ClearUserHook extends BaseModelListener<User>
2) ClearOrganizationHook extends BaseModelListener<Organization>

And registered the two listeners in portal.properties file. The listeners are registered and invoking properly, whenever create/update/delete operation performed for user_ & organization_ tables.

But the issue is:
The custom entities are not loading. I am getting the below runtime exception:
ERROR [PortletBeanLocatorUtil:38] BeanLocator is null for servlet context

I added the my service jars in tomcat\lib\ext folder and hook project lib folder as well. How to load my service classes to perform operations.
Please help me..!!

Thanks,
Rajashekar
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
BeanLocator is null is a common error that you can search the forums for a solution.

Basically it sounds like it is a timing issue; your hook is loading before the plugin providing the service is loaded.

Use liferay-plugin-package.properties of the hook to add the plugin providing the service as a required deployment context.
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi David,

Thanks for your quick reply..!!

Could you please tell me how to add plugin providing the service as a required deployment context. if you have any examples please share with me.

Thanks,
Rajashekar
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Open the file in the Liferay IDE. You'll see where to add it in the lower right corner.
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Thanks David.

I will try and let you know, the result.

Thanks,
Rajashekar
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi David,

I added
required-deployment-contexts=\ (all the required protlets)

but I am getting same error: BeanLocator is null for servlet context.

Thanks,
Rajashekar
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
That's not all contexts, it is just the root context.

If the plugin providing the service is in the webapps dir as "my-portlet", your required deployment context would be "/my-portlet".
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi David,

I have 3 portlet projects, each project having service classes. So I added 3 projects as required-deployment-contexts in liferay-plugin-package.properties file, but still I am getting same error: ERROR [PortletBeanLocatorUtil:38] BeanLocator is null for servlet context XYZService

Please check my implementation, could you please tell me how fix this issue. I not able proceed further because of this issue. I completely stuck here.

Listener class
-----------------------
public class ClearUserHook extends BaseModelListener<User> {
Book book = null;
@Override
public void onAfterRemove(User user) throws ModelListenerException {
long userId = user.getUserId();
try {
book = bookLocalServiceUtil.findAssociatedBook(userId);
if (book != null) {
try {
BookLocalServiceUtil.deleteBook(book);
} catch (SystemException e) {
e.printStackTrace();
}
}
} catch (SystemException e1) {
e1.printStackTrace();
}
}

portal.properties
-----------------------
value.object.listener.com.liferay.portal.model.User=com.liferay.hook.ClearUserHook

liferay-hook.xml
---------------------
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>


liferay-plugin-package.properties
---------------------------------------------
required-deployment-contexts=\ (added required portlet project)
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Rajashekar Katla:
liferay-plugin-package.properties
---------------------------------------------
required-deployment-contexts=\ (added required portlet project)


Again, this is where the problem is.

I have a portlet plugin which also has required deployment contexts.

My liferay-plugin-package.properties file has the following (well, I did change the names):

required-deployment-contexts=\
  my-portlet-1,\
  my-portlet-2,\
  my-portlet-3
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Yeah I did the same, even though I am getting same error.
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Well try posting the full stack trace...
thumbnail
11年前 に Jay Patel によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Regular Member 投稿: 118 参加年月日: 10/02/24 最新の投稿
Rajashekar Katla:
Hi All,

I have developed portlets with my custom entities by using service builder and generated service classes. And in my entities I have user and organization id’s.

But I have requirement like whenever the user/organization is deleted from Liferay user_ & organization_ tables, I need to delete those corresponding user/organization from my tables.
For that I created two hooks to act as listener for those tables.
1) ClearUserHook extends BaseModelListener<User>
2) ClearOrganizationHook extends BaseModelListener<Organization>

And registered the two listeners in portal.properties file. The listeners are registered and invoking properly, whenever create/update/delete operation performed for user_ & organization_ tables.

But the issue is:
The custom entities are not loading. I am getting the below runtime exception:
ERROR [PortletBeanLocatorUtil:38] BeanLocator is null for servlet context

I added the my service jars in tomcat\lib\ext folder and hook project lib folder as well. How to load my service classes to perform operations.
Please help me..!!

Thanks,
Rajashekar


Hi Rajashekar,

Are you removing service-jar from your hook's lib directory & portlet's lib directory? Because if you've placed that jar in tomcat\lib\ext, then no need to have it at other places.

-Jay.
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Thanks Jay.

I tried with u r solution but now i got below error:

ERROR [render_portlet_jsp:154] com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.xyz.liferay.serv.service.xxxLocalService' is defined
at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:70)
at com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(PortletBeanLocatorUtil.java:47)

Please help me to come out of this issue.

Thanks,
Rajashekar
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi David / Jay,

Please find the attachment for full stack trace of error, please suggest me how to come out of this issue.

Thanks,
Rajashekar
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
One of the first things you learn as a java programmer is that the top listed exception is not necessarily the one that is the problem.

Looking at the full stack trace, you find the following:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.sample.liferay.serv.service.BookLocalService' is defined


It has nothing to do with the bean locator, it has to do with an undefined bean.

Is the portlet providing the book service deployed? Did it start correctly?
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
David,

All Portlets are deployed properly and working fine. I am able to do all the functionalities of the Portets without any issues.

But I am facing issues to load those Working Portlets service classes into Hook listener. Please any body suggest me to solve this issue.

-Rajashekar
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi All,

Can any one please give me some hints for how to access Portlet service classes (custom entities) in Hook Listener class.

-Rajashekar
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Rajashekar Katla:
Can any one please give me some hints for how to access Portlet service classes (custom entities) in Hook Listener class.


That would seem to be your problem...

A hook's context is typically the portal's context, and I'm guessing the portal does not have access to your service jar.

Try dropping the service jar into the global lib/ext directory and remove the service jar from any other location in webapps, then restart the application container.

Basically I think this will boil down to just not thinking things through correctly... You can hook the listener in for Liferay's classes, but you should not be hooking in listeners for services which you manage.
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Ok, Finally I got it SOLVED.

Step1 : I placed all Portlets service jars in tomcat-7.0.23\lib\ext (Globally)

Step 2 : Also I placed service jars in hook WEB-INF\lib folder


Note:
For example A-Portlet is having service jar as A-portlet-service.jar

But A-Portlet referring B-Portlet-service.jar, So in Hook WEB-INF\lib folder only A-portlet-service.jar has to be placed not both.

Then restarted the server, and deploy the hook listener it works fine.


Thanks David and Jay for your valuables inputs.

Best Regards,
Rajashekar
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Rajashekar Katla:
Step1 : I placed all Portlets service jars in tomcat-7.0.23\lib\ext (Globally)

Step 2 : Also I placed service jars in hook WEB-INF\lib folder


If it's in the global lib/ext directory, it doesn't need to be in the WEB-INF/lib folder of the hook. A global jar is just that, available to all web applications deployed on the application server.

In fact you can possibly face other problems by doing things this way. The hook's class loader would load from the WEB-INF/lib jar (if the hook has a context, depends upon the type of hook) while every other web app would be using the one loaded from the global class loader. This can lead to conflicts...
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Thanks David,

But It is not working in that way. I tried all the various options but these steps are working fine for me. If I remove service jars from Hook lib folder again I am getting Bean Locator No bean defined error.

I placed Portlet service jars in ext\lib folder and deleted from corresponding Portlet WEB-INF\lib folder. Then I added into Hook WEB-INF\lib folder it is working perfectly.

Cheers,
- Rajashekar
11年前 に Joel Peterson によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 22 参加年月日: 10/02/18 最新の投稿
Is there a specific reason why you have your model listener hook in a different plugin than your portlet? If you are always going to have the hook and portlet deployed together than you should be able to move your hook inside of the portlet plugin so that it all deploys together. By doing it that way you should be able to keep the portlet's *service.jar in your portlet's WEB-INF/lib folder since the listener will be running in your portlet's context and will have access to your portlet's classloader, and you will not need to mess with the global lib/ext folder.

Joel
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Thanks Joel, for your valuable suggestion.

I am new to Liferay development, I don't know know how to create listener in portlet. I searched in Liferay Forum then i come to know i need to create a hook for listener. That is why i implemented a hook plugin. Could you please tell me how to create listener in portlet ? If you have sample code pls share with me!

Thanks,
Rajashekar
11年前 に Joel Peterson によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 22 参加年月日: 10/02/18 最新の投稿
You just need to merge your hook project into your portlet project. I listed out the three files that you would need to copy in to your portlet project.
  • Move <hook-project>/docroot/WEB-INF/liferay-hook.xml to <portlet-project>/docroot/WEB-INF/liferay-hook.xml
  • Move <hook-project>/docroot/WEB-INF/src/portal.properties to <portlet-project>/docroot/WEB-INF/src/portal.properties
  • Move <hook-project>/docroot/WEB-INF/src/.../YourListenerClass.java to <portlet-project>/docroot/WEB-INF/src/.../YourListenerClass.java


When you deploy your portlet, if you watch the server logs it should mention that it is deploying your portlet and it should also mention that it is deploying a hook. Make sure that you undeploy your standalone hook first though so that you do not have the same listener running twice.

If you want to look at an example of a hook in a portlet plugin, Liferay's Mail portlet available here, Liferay CE Official Plugins, is a portlet with a hook inside of it.

Joel
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Thank you so much Joel.

Sure I will try and let you know.

Best Regards,
Rajashekar
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
Hi Joel,

I did same as you suggested, but it is not working. I got the below error and portlet not loading. Pls tell me how to fix this ?

The below error keep on printing on console, until I stop the browser to load.

at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)


Thanks,
Rajashekar
11年前 に Joel Peterson によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 22 参加年月日: 10/02/18 最新の投稿
Is there an error above that repeated line in your logs?

Also, what does it say when you deploy your plugin? Does it say that it successfully deployed the portlet and the hook?
11年前 に Rajashekar Katla によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 16 参加年月日: 12/07/20 最新の投稿
yeah, the portlet deployed successfully without any issue. But while accessing the portlet i am getting this runtime exceptions and the browser keep on loading the portlet but nothing is displayed on browser but on console the exception keep on printing ?

Thanks,
Rajashekar
11年前 に Joel Peterson によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

New Member 投稿: 22 参加年月日: 10/02/18 最新の投稿
Have you removed your portlet's service jar from the server's lib/ext folder and placed it back into your portlet's WEB-INF/lib folder and then restarted your server?
thumbnail
11年前 に Jay Patel によって更新されました。

RE: ISSUE WITH MODEL LISTENER HOOK

Regular Member 投稿: 118 参加年月日: 10/02/24 最新の投稿
Glad that it has worked for you Rajashekar.

-Jay.