Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Guru k
Get Portlet Id with Portlet Name
April 15, 2012 9:59 AM
Answer

Guru k

Rank: Junior Member

Posts: 64

Join Date: February 7, 2012

Recent Posts

Hi,

How to get the portlet id of other portlets in the page with portlet name in jsp.

Thanks
Guru
Juhi Kumari
RE: Get Portlet Id with Portlet Name
April 16, 2012 4:47 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi Guru,
Use this one.
1List<Portlet> portletList = PortletLocalServiceUtil.getPortlets(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2                String portletId = null;
3                String portletName = null;
4         for(Portlet portlet : portletList){
5            portletId =  portlet.getPortletId();
6                        portletName = portlet.getPortletName();
7         }


Thanks & Regards
Juhi
Guru k
RE: Get Portlet Id with Portlet Name
April 16, 2012 5:37 AM
Answer

Guru k

Rank: Junior Member

Posts: 64

Join Date: February 7, 2012

Recent Posts

Hi Juhi,

Thanks for the reply. But "portlet.getPortletName()" returns null...

Is there a way to get instance id of all the portlets in the page.

Thanks
Guru
Juhi Kumari
RE: Get Portlet Id with Portlet Name
April 17, 2012 1:33 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi Guru,
For me its working fine. Now try this one
 1List<Portlet> portletList = null;
 2try{
 3    portletList =PortletLocalServiceUtil.getPortlets();
 4}catch(Exception e){}
 5for(Portlet portlet : portletList){
 6    System.out.println("Portlet instance Id >>> "+portlet.getInstanceId());
 7        System.out.println("Portlet Display Name >>> "+portlet.getDisplayName());
 8    System.out.println("Portlet Id >>> "+portlet.getPortletId());
 9    System.out.println("Portlet Name >>> "+portlet.getPortletName());
10      
11}


Thanks & Regards
Juhi
Guru k
RE: Get Portlet Id with Portlet Name
April 17, 2012 5:29 AM
Answer

Guru k

Rank: Junior Member

Posts: 64

Join Date: February 7, 2012

Recent Posts

Hi Juhi,

Thanks... now i am getting the Portlet name but still the Instance id comes as null...

Regards
Guru
the denu
RE: Get Portlet Id with Portlet Name
July 10, 2012 7:32 AM
Answer

the denu

Rank: New Member

Posts: 20

Join Date: July 5, 2012

Recent Posts

I have also this issue, that InstanceId is null. It is not null when comes to porltets built in Liferay. Our own portlet has his entry in getPortlets() but must not be instantiated as getInstanceId returns null. How can we instantiate our portlet?
Emanuele Ivaldi
RE: Get Portlet Id with Portlet Name
July 10, 2012 7:58 AM
Answer

Emanuele Ivaldi

Rank: New Member

Posts: 7

Join Date: July 2, 2012

Recent Posts

 1
 2    private String getPortletIdByName(String portletName){
 3        //logger.info("searching for portlet with name " + portletName);
 4        List<Portlet> list = PortletLocalServiceUtil.getPortlets();
 5       
 6        for(int i=0;i<list.size();i++){
 7       
 8            try{   
 9                //logger.info(list.get(i).getDisplayName() + " - ");
10                if(list.get(i).getDisplayName().equalsIgnoreCase(portletName)){
11                    //logger.info("portlet found");
12                    return list.get(i).getPortletId();
13                }
14            }catch(Exception e){
15                logger.error(e.getMessage());
16            }
17        }
18        //logger.info("portlet not found");
19        return null;
20    }



i wrote this to put all my istanceable and non portlets into the pages through my hook