Sunday, February 8, 2015

Finder method for Service Builder in Liferay

Today we will Discuss Finder method for Service Builder in Liferay

In my Previous article Service Builder in Detail we see that liferay created basic CRUD method automatically but what if we want to add our custom method in Liferay services . There are many ways but creating Finder method is the simplest one.

Lets Start this step by step:-

Step 1:-Create service.xml
You can create service as mention in my previous article Service Builder in Detail .Today we add finder method in my Services:-


Just Focus on these lines:-


1) <finder name="Mobile" return-type="Collection">
a) name="Mobile"
This is the name by which method is Created. Our method is Created by name 
findByMobile(). findBy is automatically prepended by liferay.

Note=> The name must be Capital otherwise method is created as findBymobile() 
which is not follow java camel case convention.

b) return-type="Collection"
return type of our method Collection represent List<T> in this case List<Student>.

2)<finder-column name="mobileno"></finder-column>
Column-name represent on which column you want to apply conditions.

After doing this just build your service and refresh your project.

Step 2:-Check Point

At this point liferay create our method in two places:-

1)StudentPersistence (Interface)
(under web-inf/services/com/aditya/services/persistence)

This interface contain many overloaded method of same name like:-
Their are other method also like removeByMobile, countByMobile etc.

2)StudentPersistenceImpl (Class)
(under web-inf/src/com/aditya/services/persistence)
This contain the implementation of StudentPersistence interface.

Step 3:-Expose method to Util Classes

Till now our method is not available to LocalServiceUtil Class.We have to expose it.Open StudentLocalServiceImpl Class. This class is just blank provide implementation of your method here so that it can be available by Util Class.

As you see in implementation we just call the method from interface thats it.
Now again build services and that it .Your method is now available to StudentLocalServiceUtil Class.

You can download source code from Finder method for service builder in lifeary

Hope this will help....

Related Post:-

Liferay Service Builder in Detail

Custom Sql in Liferay

Custom Sql with two table in Liferay

Many To Many Relationship mapping in Liferay Services

Liferay Service Builder in Detail

How to install Maven

Creating Portlet/Services using Maven

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!