Foros de discusión

RE: adding custom methods in Hook environment

thumbnail
Dave Weitzel, modificado hace 13 años.

adding custom methods in Hook environment

Regular Member Mensajes: 208 Fecha de incorporación: 18/11/09 Mensajes recientes
I am adding functionality to the calendar portlet using IDE and a hook project.
I am using Liferay In action a s a reference along with as many wiki and ofurm posts as possible!
I have written a new class in <my.custom package>.MyCalEvent.LocalServiceImpl which extends the CalEventLocalServiceWrapper
and in initially I just overrided the getEvent method to trace the event id

a) this only worked once I copied the class file from my portlet structure to the ROOT/WEB-INF/classes folder - how do we set up the system to detected it in the correct place?

I then added a new method that I want to use - at this stage I am not adding any new fields or anything so have no service builder elements.
(this is a skeleton of the real code I want to add here.)


public List<CalEvent> getMyEvents()
throws PortalException, SystemException {
System.out.println("## get MY events " );
int count = this.getCalEventsCount();
List<CalEvent> events = this.getCalEvents(0, count);
return events;
}


However when I try to access this in my jsp file
List myevents = MyCalEventLocalServiceImpl.getMyEvents();
I get the age old error:
"Cannot make a static reference to the non-static method getMyEvents() from the type MyCalEventLocalServiceImpl" which I sort of expected.

b) So what else do I have to do in order to call this method correctly?
Do I have to have a Wrapper class? Or a Util class? If so what do they look like?

Again this is not extending the data (that is next job) just adding new methods to existing service

Thanks
thumbnail
Andrés Cerezo, modificado hace 12 años.

RE: adding custom methods in Hook environment

Junior Member Mensajes: 92 Fecha de incorporación: 11/11/10 Mensajes recientes
Hello, I'm trying the same, can you send me the liferay-hook.xml ? I have problems!!
thumbnail
Puj Z, modificado hace 12 años.

RE: adding custom methods in Hook environment

Regular Member Mensajes: 220 Fecha de incorporación: 14/01/10 Mensajes recientes
why don't you simply make your method static?
Laxman Rana, modificado hace 12 años.

RE: adding custom methods in Hook environment

Junior Member Mensajes: 38 Fecha de incorporación: 1/03/12 Mensajes recientes
@dave

have u done with u r problem...m facing the same prob.....i am getting undefined method error...
thumbnail
Joaquin Cabal, modificado hace 12 años.

RE: adding custom methods in Hook environment

Regular Member Mensajes: 106 Fecha de incorporación: 7/09/09 Mensajes recientes
Hi Dave,
I think that Liferay hook plugin only works for override existing methods, if you want to create a new method or functionality , you need to create an Ext plugin

The class that have the static methods is MyCalEvent.LocalServiceUtil, but sure not have your new method, because that class populates with service builder
thumbnail
Vilmos Papp, modificado hace 12 años.

RE: adding custom methods in Hook environment

Liferay Master Mensajes: 529 Fecha de incorporación: 21/10/10 Mensajes recientes
The problem with this is that the method is not static, so you have 2 choices:

1.) Modify your method to be static
2.) Create an instance from your class and call that instance's method.

Anyway I would suggest you to check how the service/implementation layers are handled in the portal, what are the naming concepts and how to use the *LocalServiceUtil classes as from what you have written it's not really clear to me why do you extend the wrapper when you try to override the implementation.