adding custom methods in Hook environment?
Asked Answered
S

2

2

i am adding a new method into CalEventLocalServiceImpl using hook...

my code is ..

public class MyCalendarLocalServiceImpl extends CalEventLocalServiceWrapper {

    public MyCalendarLocalServiceImpl(CalEventLocalService calEventLocalService) {
        super(calEventLocalService);
        // TODO Auto-generated constructor stub
    }

    public List getUserData(long userId) throws SystemException{
        DynamicQuery query=DynamicQueryFactoryUtil.forClass(CalEvent.class)
        .add(PropertyFactoryUtil.forName("userId").eq(userId));
        List deatils=CalEventLocalServiceUtil.dynamicQuery(query);

        return deatils;
    }
}

liferay-hook.xml:

<service>
    <service-type>
        com.liferay.portlet.calendar.service.CalEventLocalService
    </service-type>
    <service-impl>
        com.liferay.portlet.calendar.service.impl.MyCalendarLocalServiceImpl
    </service-impl>
</service>

my question is how to use getUserData from jsp file. Can anybody help me out....

i think u didn't gt my question...i want list of events based on USERID from Calendar ...to achieve this task what i need to do??

Stanza answered 17/3, 2012 at 4:29 Comment(0)
G
4

I assume getUserData() is not overridden but a new method (can't look up currently). This is not what you can do when overriding a service. Instead you'd have to add a new Service and make it available to the portal.

Remember that a customized ("hooked") jsp is running in the portal classloader, while your overloaded service is running in the hook's classloader. Thus, if you create a new service and make the service.jar available to Liferay (e.g. on the global classpath) you can call it from JSPs. The interface of Liferay services can not be extended through an overloaded service.

In case getUserData() is already in the interface (as I said I can't look up currently), you just need to call the CalendarLocalServiceUtil from your jsp and it will be delegated to your wrapper.

Grazia answered 17/3, 2012 at 19:24 Comment(2)
You can't add it "in" it, but it's no problem to just create a separate service.Grazia
Create a whole new service (don't just extend an existing one with a new method). Then put the *-service.jar that you get from this plugin on the global classpath so that Liferay (the root web application) can reach into it. Then use this service from your jspGrazia
Z
3

Just to add to Olaf's answer and comments...

if you you want to extend CalEventLocalService service with just "getUsetData" and use it in one jsp than building your own service might be overkill. Simply put your code from "getUserData" in jsp. Otherwise follow Olaf's suggestions.

Zeb answered 19/3, 2012 at 9:18 Comment(1)
Can you please see this and help me...#9765140Disarm

© 2022 - 2024 — McMap. All rights reserved.