Foros de discusión

[RESOLVED] Load Custom Portlet Plugin via AJAX from Dockbar

thumbnail
Barry Rowe, modificado hace 13 años.

[RESOLVED] Load Custom Portlet Plugin via AJAX from Dockbar

New Member Mensajes: 14 Fecha de incorporación: 22/10/10 Mensajes recientes
Desired Functionality:

I would like to provide a link in the dockbar that will load a custom Portlet Plugin into a Dockbar Underlay. I want this to work just like the "addApplication" feature that loads the Layout_Configuration portlet.

What I'm trying:
I have a created a simple portlet plugin called about-portlet and the liferay-portlet.xml <portlet> entry looks like below:
<portlet>
		<portlet-name>about-portlet</portlet-name>
		<icon>/icon.png</icon>			
		<instanceable>false</instanceable>
		<ajaxable>true</ajaxable>					
		<header-portlet-css>/css/portlet.css</header-portlet-css>
		<footer-portlet-javascript>
			/js/javascript.js
		</footer-portlet-javascript>
		<css-class-wrapper>aboutportlet-portlet</css-class-wrapper>		
		<add-default-resource>true</add-default-resource>		
		<system>true</system>
	</portlet>


This portlet works as expected (I set <system> to false and am able to add the portlet to any of my pages and it shows just fine).

I have a hook plugin that overrides the view.jsp for the Dockbar, and I have added what is almost a duplicate of the AUI javascript function that loads the addApplication portlet (p_p_id = 87). The following appears just before the addApplication.on('click'.... code in /dockbar/view.jsp:

var aboutPortal = A.one('#aboutPortal');
										if(aboutPortal){
											aboutPortal.on('click',
												function(event){
													alert(themeDisplay.getPlid());																										
													if(!Liferay.Dockbar.aboutUnderlay){																																														
														instance.addUnderlay(
															{																
																className: 'about_portal',
																io: { 
																		data: { p_l_id: themeDisplay.getPlid(),
                                                                            	p_p_id: 'aboutportlet_WAR_aboutportlet',
                                                                            	p_p_state: 'exclusive'                                                      
                                                                          	  },
                                                                    	uri: themeDisplay.getPathMain() + '/portal/render_portlet'                                                                    	
                                                                    },
                                                                 name: 'aboutUnderlay',
                                                                 width: '400px'
                                                             }); 
                                                        //end instance.addUnderlay 			
													}
													else {
														Liferay.Dockbar.aboutUnderlay.show();
													}													
													Liferay.Dockbar.aboutUnderlay.focus();
												});
											//end event definition for aboutPortal.on()
										}


I also know this js is good, as It loads and shows the "addApplication" portlet or the login portlet just fine if I change the p_P_id parameter to 87 or 58 respectively.

It seems there would be a way to configure a portlet plugin to be available to the render_portlet action WITHOUT having it added to a Layout somewhere within the portal.

Additional Notes:
-If I make the portlet a non-system portlet (<system>false</system>) and add it to a page, then call my js from that page, the portlet shows in the Underlay just fine.
-I have tried removing the p_l_id paramter from my AJAX call so that the render_portlet action does not look at a specific layout for the portlet, and it still does not work.
-I do receive the following JS error when the portlet has not been added to any page which I believe is the Underlay initialization blowing up due to a null portlet instance:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER)" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"

-My portlet plugin is a liferay MVCPortlet

-I have been able to debug and watch the RenderPortletAction fire and complete with no errors when I make the ajax call.
-Using Liferay 6.0.4

What am I missing? Thank you!
thumbnail
Barry Rowe, modificado hace 13 años.

RE: Load Custom Portlet Plugin via AJAX from Dockbar (Respuesta)

New Member Mensajes: 14 Fecha de incorporación: 22/10/10 Mensajes recientes
I now have this working. I found the answer in this thread thanks to the post by Jelmer Kuperas:

What I was missing:

&lt;%@page import="com.liferay.portlet.PortletURLFactoryUtil" %&gt;

...

PortletURL url = PortletURLFactoryUtil.create(request, "aboutportlet_WAR_aboutportlet", layout.getPlid(), PortletRequest.RENDER_PHASE);
    	url.setWindowState(LiferayWindowState.EXCLUSIVE); 



...

uri: '&lt;%= url.toString()%&gt;'


This works without having to add the portlet to a "hidden" page/community.
Srilalitha Pusuluri, modificado hace 11 años.

RE: Load Custom Portlet Plugin via AJAX from Dockbar

New Member Mensajes: 11 Fecha de incorporación: 24/02/12 Mensajes recientes
Hi Barry,

I have added my Portlet to the dockbar the same way. But it opens the portlet on the same page , not as a pop-up. Any suggestions ?
thumbnail
Barry Rowe, modificado hace 11 años.

RE: Load Custom Portlet Plugin via AJAX from Dockbar

New Member Mensajes: 14 Fecha de incorporación: 22/10/10 Mensajes recientes
If you're using the AUI script to load the portlet in an Underlay, it will be displayed on the same page, much like the Layouts menu when you select "Page Layout" under Manage.

If you would like to open the portlet in a true popup/a new tab, you can use the "target" attribute of your anchor tag.

The PortletURL you build will be the same, you'll just need to manually add the parameters we add wihin the AUI script.

You'll need to manually add the following parameters to your PortletURL object:

...
p_l_id: themeDisplay.getPlid(),    //This is the layout id
p_p_id: 'aboutportlet_WAR_aboutportlet',   //This is the portletId
p_p_state: 'exclusive'     //This is the type of state that the View should render.
...


Then you just set your PortletURL object as the href for an anchor tag like so:


<a href="<%=url%>" target="_new">Open My Portlet</a>


I hope this helps!