Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...