Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

liferay 6 - adding custom methods in Hook environment?

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...