Fórumok

Nyitólap » Liferay Portal » English » 3. Development

Kombinált nézet Egyszerű nézet Fa-nézet
Szálak [ Előző | Következő ]
toggle
Ilya V. Kalujny
Is there a way of reading portlet preferences on portlet start-up?
2010. május 5. 2:35
Válasz

Ilya V. Kalujny

Rangsorolás: New Member

Hozzászólások: 3

Csatlakozás dátuma: 2009. szeptember 14.

Legújabb hozzászólások

Hello there!

Suppose I`m developing an instanceable portlet with owned-by-group=false, unqiue-per-layout=true. Is there any legitimate way of retrieving portlet preferences for all pages and users at portlet deploy time?

Thanks,
Ilya.
Tomáš Polešovský
RE: Is there a way of reading portlet preferences on portlet start-up?
2010. május 5. 4:34
Válasz

Tomáš Polešovský

LIFERAY STAFF

Rangsorolás: Expert

Hozzászólások: 492

Csatlakozás dátuma: 2009. február 13.

Legújabb hozzászólások

Hello Ilya,

there could be 2 situations:
1, portlet is deployed for the first time - it's placed nowhere in the portal => has no preferences defined
2, portlet is redeployed => maybe portlet is placed somewhere, you can try to use PortletPreferencesFinderUtil.findByPortletId(String portletId)

-- tom
Ilya V. Kalujny
RE: Is there a way of reading portlet preferences on portlet start-up?
2010. május 5. 6:17
Válasz

Ilya V. Kalujny

Rangsorolás: New Member

Hozzászólások: 3

Csatlakozás dátuma: 2009. szeptember 14.

Legújabb hozzászólások

Hey again and thanks for reply.

When trying to use

PortletPreferencesFinderUtil.findByPortletId

in the init() method, I get the infamous

No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

exception. Seems like we need to get Hibernate Session from liferay internals.

Thanks,
Ilya.
Tomáš Polešovský
RE: Is there a way of reading portlet preferences on portlet start-up?
2010. május 5. 6:27
Válasz

Tomáš Polešovský

LIFERAY STAFF

Rangsorolás: Expert

Hozzászólások: 492

Csatlakozás dátuma: 2009. február 13.

Legújabb hozzászólások

Oh no, Finders.

Mea culpa. Finders can be used only from the *ServiceImpl classes emoticon

Try to create a DynamicQuery and run it, e.g.:

1DynamicQuery query = DynamicQueryFactoryUtil.forClass(PortletPreferences.class)
2  .add(PropertyFactoryUtil.forName("portletId").eq(yourPortletId);
3
4List preferences = PortletPreferencesLocalServiceUtil.dynamicQuery(query);


-- tom
Ilya V. Kalujny
RE: Is there a way of reading portlet preferences on portlet start-up?
2010. május 5. 7:57
Válasz

Ilya V. Kalujny

Rangsorolás: New Member

Hozzászólások: 3

Csatlakozás dátuma: 2009. szeptember 14.

Legújabb hozzászólások

Thanks a lot this did it! Also had to use special class loader.

 1
 2ClassLoader cl = PortalClassLoaderUtil.getClassLoader();
 3DynamicQuery query = DynamicQueryFactoryUtil.forClass(
 4        PortletPreferences.class, cl).add(
 5        PropertyFactoryUtil.forName("portletId").like("%LineChart%"));
 6
 7List<Object> preferences = PortletPreferencesLocalServiceUtil.dynamicQuery(query);
 8
 9System.out.println("Preferences are: " + preferences
10        + ", size is: " + preferences.size());
11
12for (Object preferencesPart : preferences) {
13        System.out.println(((PortletPreferences) preferencesPart).getPreferences());
14
15etc etc....


Cheers.
Enzo Ferrari
RE: Is there a way of reading portlet preferences on portlet start-up?
2012. május 17. 9:35
Válasz

Enzo Ferrari

Rangsorolás: New Member

Hozzászólások: 19

Csatlakozás dátuma: 2012. május 17.

Legújabb hozzászólások

Ilya V. Kalujny:
Thanks a lot this did it! Also had to use special class loader.

 1
 2ClassLoader cl = PortalClassLoaderUtil.getClassLoader();
 3DynamicQuery query = DynamicQueryFactoryUtil.forClass(
 4        PortletPreferences.class, cl).add(
 5        PropertyFactoryUtil.forName("portletId").like("%LineChart%"));
 6
 7List<Object> preferences = PortletPreferencesLocalServiceUtil.dynamicQuery(query);
 8
 9System.out.println("Preferences are: " + preferences
10        + ", size is: " + preferences.size());
11
12for (Object preferencesPart : preferences) {
13        System.out.println(((PortletPreferences) preferencesPart).getPreferences());
14
15etc etc....


Cheers.


Hi Ilya!!
I tried your code, but it gives me an Exception:

 1
 216:15:47,782 ERROR [DynamicQueryFactoryImpl:83] Unable find model javax.portlet.impl.PortletPreferencesImpl
 3java.lang.ClassNotFoundException: javax.portlet.impl.PortletPreferencesImpl
 4    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
 5    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
 6    at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.getImplClass(DynamicQueryFactoryImpl.java:78)
 7    at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.forClass(DynamicQueryFactoryImpl.java:39)
 8    at com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil.forClass(DynamicQueryFactoryUtil.java:29)
 9    at cl.forexchile.portlet.solicitademo.DemoPortlet.init(DemoPortlet.java:209)
10    at javax.portlet.GenericPortlet.init(GenericPortlet.java:107)
11    at com.liferay.portlet.InvokerPortletImpl.init(InvokerPortletImpl.java:245)
12    at com.liferay.portlet.PortletInstanceFactoryImpl.init(PortletInstanceFactoryImpl.java:216)
13    at com.liferay.portlet.PortletInstanceFactoryImpl.create(PortletInstanceFactoryImpl.java:139)
14    at com.liferay.portlet.PortletInstanceFactoryUtil.create(PortletInstanceFactoryUtil.java:40)
15    at com.liferay.portal.deploy.hot.PortletHotDeployListener.initPortletApp(PortletHotDeployListener.java:522)
16    at com.liferay.portal.deploy.hot.PortletHotDeployListener.doInvokeDeploy(PortletHotDeployListener.java:260)
17    at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:101)
18    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:109)
19    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:182)
20    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:38)
21    at com.liferay.portal.kernel.servlet.PortletContextListener.doPortalInit(PortletContextListener.java:99)
22    at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
23    at com.liferay.portal.kernel.util.PortalLifecycleUtil.flushInits(PortalLifecycleUtil.java:41)
24    at com.liferay.portal.servlet.MainServlet.initPlugins(MainServlet.java:803)
25    at com.liferay.portal.servlet.MainServlet.init(MainServlet.java:355)
26    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
27    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
28    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
29    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
30    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
31    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
32    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
33    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
34    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
35    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
36    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
37    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
38    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
39    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
40    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
41    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
42    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
43    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
44    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
45    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
46    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
47    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
48    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
49    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
50    at java.lang.reflect.Method.invoke(Method.java:597)
51    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
52    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)


Do I have to import any jar in my portlet?

greetings
Tomáš Polešovský
RE: Is there a way of reading portlet preferences on portlet start-up?
2012. június 20. 2:43
Válasz

Tomáš Polešovský

LIFERAY STAFF

Rangsorolás: Expert

Hozzászólások: 492

Csatlakozás dátuma: 2009. február 13.

Legújabb hozzászólások

Hi Enzo,

you are passing wrong PortletPreferences class. You should use com.liferay.model.PortletPreferences instead of javax.portlet.PortletPreferences.

-- tom
Enzo Ferrari
RE: Is there a way of reading portlet preferences on portlet start-up?
2012. június 28. 14:26
Válasz

Enzo Ferrari

Rangsorolás: New Member

Hozzászólások: 19

Csatlakozás dátuma: 2012. május 17.

Legújabb hozzászólások

Tomáš Polešovský:
Hi Enzo,

you are passing wrong PortletPreferences class. You should use com.liferay.model.PortletPreferences instead of javax.portlet.PortletPreferences.

-- tom


Thanks Tom
that was the problem

best regards