Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Preben Ludviksen
Portlet Instance ID
25 de Novembro de 2007 04:18
Resposta

Preben Ludviksen

Ranking: New Member

Mensagens: 7

Data de entrada: 7 de Novembro de 2007

Mensagens recentes

I'm making a portlet with some properties stored in a xml-file. I want to have unique settings for each instance of my portlet. Each instance obviously have an instance id, so I was just wondering how I can get this id in my code, as I need it to read/write the right properties?
Roman Hoyenko
RE: Portlet Instance ID
26 de Novembro de 2007 08:13
Resposta

Roman Hoyenko

Ranking: Liferay Master

Mensagens: 868

Data de entrada: 8 de Outubro de 2007

Mensagens recentes

String portletId = portletDisplay.getId();
Lester Chua
RE: Portlet Instance ID
26 de Novembro de 2008 02:05
Resposta

Lester Chua

Ranking: New Member

Mensagens: 8

Data de entrada: 29 de Novembro de 2006

Mensagens recentes

Roman Hoyenko:
String portletId = portletDisplay.getId();


And may I know what is "portletDisplay"?
For all I know it can be a variable for any bean in the world with a getId() method.

Is there a more concrete answer?
François Cassin
RE: Portlet Instance ID
27 de Novembro de 2008 02:28
Resposta

François Cassin

Ranking: New Member

Mensagens: 9

Data de entrada: 23 de Setembro de 2008

Mensagens recentes

Hi Lester,

Have you tried this :

ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
String portletId = portletDisplay.getId();

Where req is a RenderRequest.

Hope this helps
Luc Pons
RE: Portlet Instance ID
3 de Dezembro de 2008 06:41
Resposta

Luc Pons

Ranking: Junior Member

Mensagens: 70

Data de entrada: 3 de Dezembro de 2008

Mensagens recentes

François Cassin:
Hi Lester,

Have you tried this :

ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
String portletId = portletDisplay.getId();

Where req is a RenderRequest.

Hope this helps


Hi,

I'm not sure of they way you meant your code, but it seemed to me that it fit my requirements.
I'm trying to develop a portlet which would add another portlet on the layout. I want then to get it's instanceId

I'm doing ...


 1
 2
 3            //get the layout
 4            Layout layout = LayoutLocalServiceUtil.getLayout(11131);
 5            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
 6
 7
 8            //Add the portlet
 9            ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
10            layoutTypePortlet.addPortletId(themeDisplay.getUserId(), "9");
11
12            //"save" the changes
13            LayoutLocalServiceUtil.updateLayout(layout.getGroupId(),
14                    layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
15[b]
16            //Your code
17            PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
18            String portletId = portletDisplay.getId();
19            System.out.println("l'id trouvé est : " + portletId);
20[/b]


In the end, the portledId is the empty string ""

From there, i have a question
If we add two portlets on the layout, how coul we get the instanceIds ? Or maybe the portletDisplay.getId() returns the id of the last instance?

:/

Thx
Luc
Bob Baird
RE: Portlet Instance ID
18 de Abril de 2011 20:59
Resposta

Bob Baird

Ranking: New Member

Mensagens: 2

Data de entrada: 8 de Fevereiro de 2011

Mensagens recentes

Using Liferay 6.0, I am looking to retrieve the portlet instance id for an instanceable portlet. I know this thread is old, but thought I'd reply to it since I didn't find a direct answer to my question after checking several search results. I am trying to display the instance id in an event processing method (IPC) to verify which instance of the portlet is receiving a particular event. After several rounds in my eclipse debugger, the following code does the trick:

String s = (String) request.getAttribute("PORTLET_ID");

request is the EventRequest parameter from the @ProcessEvent method, but the same code works using the RenderRequest parameter in the doView method as well.

Resulting instance id is the fully qualified instance id (portletId from the portletpreferences table.
Example: catcherportlet_WAR_ipcbaseballcatcherportlet_INSTANCE_Zxu7

Thx
Jignesh Vachhani
RE: Portlet Instance ID
18 de Abril de 2011 22:57
Resposta

Jignesh Vachhani

Ranking: Liferay Master

Mensagens: 780

Data de entrada: 10 de Março de 2008

Mensagens recentes

Hi Bob
You can get portletpreference object anf through that object you can get portlet instance id.
See below code :
PortletPreferences preferences = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");
if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}

Subhash Pavuskar
RE: Portlet Instance ID
26 de Setembro de 2012 05:45
Resposta

Subhash Pavuskar

Ranking: Regular Member

Mensagens: 234

Data de entrada: 12 de Março de 2012

Mensagens recentes

Hi all ,

How to get the portlet instance id which is inside the nested portlet.

I have a Nested portlet which contains couple of portlets(like Asset Pubisher and KB article).

From the Lay out i'm able to get the Nested Portlet Information. But i don;t know how to get the children's information which is inside the Nested Portelt. Please help me on this. Below is the code snippet i used to get the Nested Portelt Info from the LayOut.


 1Layout l=LayoutLocalServiceUtil.getLayout(themeDisplay.getPlid());
 2LayoutTypePortlet articleLayoutTypePortlet = (LayoutTypePortlet)l.getLayoutType();
 3List<Portlet> allPortlets = articleLayoutTypePortlet.getAllPortlets(column);
 4for (Portlet p: allPortlets)
 5{
 6//System.out.println("Portlet Id is"+p.getRootPortletId());
 7if(PortletKeys.NESTED_PORTLETS.equals(p.getRootPortletId()))
 8{
 9//I'm able to come up to here. But don't know how to get children's information from this onwards.
10}
11}