Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Armando Gallo
ServiceBuilder - adding search methods in a custom portlet
April 21, 2010 2:10 AM
Answer

Armando Gallo

Rank: New Member

Posts: 18

Join Date: December 28, 2007

Recent Posts

Hi,

i created an address-book portlet using service builder; In this portlet i can view,add,modify and delete records from my table but i don't know how to develop a search functionality within this portlet.

I checked administration portlet's code (users list) but i can't understand how to report it to my portlet.

I noticed that in the classes generated by service.xml there's no "search" method. In the wiki's section dedicated to servicebuilder i've seen a schema in which the XXXLocalService class has a search method.

Is this method automatically generated by servicebuilder? Maybe I must write something else in the service.xml

Instead, how can i add search functionality to my portlet ?

Thank you
Babu Janarthanan Ramachandran
RE: ServiceBuilder - adding search methods in a custom portlet
April 21, 2010 2:21 AM
Answer

Babu Janarthanan Ramachandran

Rank: Regular Member

Posts: 132

Join Date: July 30, 2008

Recent Posts

Hi,
which version of liferay you are using.

if you want to add search functionality, you can generate finder method using service.xml


<finder name="name" return-type="Collection">
<finder-column name="coulmnname" />
</finder>




Thx,
Babu
Armando Gallo
RE: ServiceBuilder - adding search methods in a custom portlet
April 21, 2010 2:37 AM
Answer

Armando Gallo

Rank: New Member

Posts: 18

Join Date: December 28, 2007

Recent Posts

Thanks Babu, I'm using LR 5.2.3 in ext environment

I successfully generated the code with finder tag. I see the "findByName" (more than one) method in AddressBookEntryUtil in 'persistence' package but how can i use it ?

Do i have to develop my search method in xxxlocalserviceutil in which i call findbyname?

Can you post a code for example?

probably, it's easier than it seems but i had no coffee this morning emoticon

Thank you
Babu Janarthanan Ramachandran
RE: ServiceBuilder - adding search methods in a custom portlet
April 21, 2010 3:02 AM
Answer

Babu Janarthanan Ramachandran

Rank: Regular Member

Posts: 132

Join Date: July 30, 2008

Recent Posts

you have to develop a method in your serviceimpl.java, and then access the util method.

assuming that you have given 2 columns in the finder tag.

public List getByName (String abc, String sample) throws PortalException, SystemException {
return AddressBookEntryUtil.findByName(abc, sample);
}

you can take a look @ portal source for more clarity.

Thx,
Babu
Armando Gallo
RE: ServiceBuilder - adding search methods in a custom portlet
April 21, 2010 5:30 AM
Answer

Armando Gallo

Rank: New Member

Posts: 18

Join Date: December 28, 2007

Recent Posts

Hi Babu,
thanks for your reply and example. I'm getting some errors when i call my method;

My code:

in AddressBookLocalServiceUtil.java

1
2public static List<AddressBookEntry> getByName(String title)
3    throws PortalException, SystemException {
4        return AddressBookEntryUtil.findByTitle(title);
5    }


and then in view_address.jsp:

1
2List<AddressBookEntry> addresses = (List<AddressBookEntry>)AddressBookLocalServiceUtil.getByName("a string");


I'm getting this error:
 1
 2Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
 3    at com.liferay.portal.spring.hibernate.SessionFactoryInvocationHandler.invoke(SessionFactoryInvocationHandler.java:68)
 4    at $Proxy1.getCurrentSession(Unknown Source)
 5    at com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl.openSession(SessionFactoryImpl.java:61)
 6    at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.openSession(BasePersistenceImpl.java:70)
 7    at com.ext.portlet.addressbook.service.persistence.AddressBookEntryPersistenceImpl.findByTitle(AddressBookEntryPersistenceImpl.java:754)
 8    at com.ext.portlet.addressbook.service.persistence.AddressBookEntryUtil.findByTitle(AddressBookEntryUtil.java:147)
 9    at com.ext.portlet.addressbook.action.AddressBookLocalServiceUtil.getByName(AddressBookLocalServiceUtil.java:95)
10    at org.apache.jsp.html.portlet.ext.address_005fbook.view_005faddress_jsp._jspService(view_005faddress_jsp.java:702)
11.....
12....
13....
14more and more

what's my fault?
thank you
Babu Janarthanan Ramachandran
RE: ServiceBuilder - adding search methods in a custom portlet
April 21, 2010 9:27 PM
Answer

Babu Janarthanan Ramachandran

Rank: Regular Member

Posts: 132

Join Date: July 30, 2008

Recent Posts

you should write your code in AddressBookLocalServiceImpl.java.

public static List<AddressBookEntry> getByName(String title)
throws PortalException, SystemException {
......
}
Navin Singh
RE: ServiceBuilder - adding search methods in a custom portlet
September 9, 2012 7:50 PM
Answer

Navin Singh

Rank: New Member

Posts: 8

Join Date: November 14, 2011

Recent Posts

As per you guys' instructions, I was able to successfully implement search indexing and open search on my custom portlet. It indexes my portlet data when running re-index process. But I have problem now, when I try to search, it gives me an exception stating "Error displaying content of type liferay open search... ", any help will be really appreciated.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!