Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Smilelws2010 lwz
Service Builder - read preference table
June 11, 2013 2:18 PM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

HI

Is it possible to read preference table for the portlet inside a method in the Liferay service builder, XxxServiceImpl.java?

If so how can we do that?

Thanks and looking forward to see the insights and possible solutions to read a name value pair from preference table in liferay.

Regards,
Smile
Sanketh Iyer
RE: Service Builder - read preference table
June 11, 2013 11:02 PM
Answer

Sanketh Iyer

Rank: New Member

Posts: 22

Join Date: February 2, 2012

Recent Posts

You can create a method with ActionRequest or Renderrequest as a parameter in your xxxLocalServiceImpl.java class.

You can fetch the preferences by using
PortletPreferences prefs = request.getPreferences();

Now you can call this method from your controller class
Smilelws2010 lwz
RE: Service Builder - read preference table
June 12, 2013 6:14 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

Thanks Sanketh for the help.

But can you get ActionRequest or RenderRequest object inyour service builder implementation class? I doubt that.

Could you help me with that. And correct me if I am wrong.

Thanks
Smile
Sanketh Iyer
RE: Service Builder - read preference table
June 13, 2013 11:30 PM
Answer

Sanketh Iyer

Rank: New Member

Posts: 22

Join Date: February 2, 2012

Recent Posts

In your controller you can use:

xxxLocalServiceUtil.yourMethod(actionRequest);

and you can have a method in your xxxLocalServiceImpl

yourMethod(ActionRequest actionRequest){}
Apoorva Prakash
RE: Service Builder - read preference table
June 14, 2013 12:47 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Smilelws2010 lwz:
HI

Is it possible to read preference table for the portlet inside a method in the Liferay service builder, XxxServiceImpl.java?

If so how can we do that?

Thanks and looking forward to see the insights and possible solutions to read a name value pair from preference table in liferay.

Regards,
Smile


Hello Smile,

With the following code snippet, you can get the preferences object in doView...
1Portlet portlet = (Portlet)renderRequest.getAttribute(WebKeys.RENDER_PORTLET);
2        PortletPreferences preferences = null;
3        try{
4            preferences =PortletPreferencesFactoryUtil.getPortletSetup(renderRequest, portlet.getPortletId());
5        }catch(SystemException se){
6            log.info(se.getMessage() + "occured in getting prefs");
7        }


Yes Sanketh mentioned it correctly, you can always pass the actionRequest or renderRequest as a argument of *LocalServiceUtil and *ServiceUtil class.

For more details about custom configurations, see this link.

HTH.

Thanka and Regards,
Apoorva Prakash
David H Nebinger
RE: Service Builder - read preference table
June 14, 2013 6:19 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 13225

Join Date: September 1, 2006

Recent Posts

Sorry, but this is really a bad idea...

SB code is meant to be used by multiple portlets. Each portlet has it's own portlet prefs (they are not shared nor overlap), so it's really a poor design to rely on the preferences of the calling portlet within your SB code...

Since the preferences belong to the SB code, you should handle them there. There's a number of different ways to accomplish this (a static singleton, spring injection, direct spring context access, etc.).
Smilelws2010 lwz
RE: Service Builder - read preference table
June 18, 2013 9:10 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

Thanks a lot Sanketh for the guidance.

I will try to do that and see how it goes.
Smilelws2010 lwz
RE: Service Builder - read preference table
June 18, 2013 9:17 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

Thanks for the information David and Apoorva.

David,
I am not trying to read the preference of the calling portlet.

I am trying to read some values stored in the SB impl class based on the parameter passed by the calling portlet. And then I will have to look up the preferences table and get other details related to the parameter passed. Is that possible?

I will try to do the suggestions or will create a separate table other than preference and will try to query that using jdbc. Please suggest if this is going nowhere.

Reagrds,
SMile

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