Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Dave Weitzel
adding custom methods in Hook environment
March 29, 2011 9:24 AM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 169

Join Date: November 18, 2009

Recent Posts

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
Andrés Cerezo
RE: adding custom methods in Hook environment
May 30, 2011 3:09 PM
Answer

Andrés Cerezo

Rank: Junior Member

Posts: 92

Join Date: November 11, 2010

Recent Posts

Hello, I'm trying the same, can you send me the liferay-hook.xml ? I have problems!!
Puj Z
RE: adding custom methods in Hook environment
May 30, 2011 11:43 PM
Answer

Puj Z

Rank: Regular Member

Posts: 199

Join Date: January 14, 2010

Recent Posts

why don't you simply make your method static?
Laxman Rana
RE: adding custom methods in Hook environment
March 16, 2012 9:39 AM
Answer

Laxman Rana

Rank: Junior Member

Posts: 42

Join Date: February 29, 2012

Recent Posts

@dave

have u done with u r problem...m facing the same prob.....i am getting undefined method error...
Joaquin Cabal
RE: adding custom methods in Hook environment
March 16, 2012 12:09 PM
Answer

Joaquin Cabal

Rank: Junior Member

Posts: 49

Join Date: September 7, 2009

Recent Posts

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
Vilmos Papp
RE: adding custom methods in Hook environment
March 16, 2012 1:51 PM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Expert

Posts: 424

Join Date: October 21, 2010

Recent Posts

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.