Fórumok

Adding portlets using JSP and jQuery

Alexandre Vaz, módosítva 11 év-val korábban

Adding portlets using JSP and jQuery

New Member Bejegyzések: 4 Csatlakozás dátuma: 2012.08.24. Legújabb bejegyzések
Hey guys, i need to make one portlet to add other portlets using JSP and jQuery, but i'm getting some troubles upon here.


The following code runs perfectly, i can add the portlet as expected. But when i click the button "Add portlet", the only element loaded in the layout, is the placeholder, where the portlet is supposed to be. Portlets added, actualy, only load when the page is refreshed. Any idea about what's going on?

<script src="http://code.jquery.com/jquery-latest.js"></script>

 <script> 
 
 
 		
 		
        AUI().use(
        	'aui-node',
            function (A){
            	
       	   		 var it = jQuery(".portlet").each(function(){
       	    			A.one('#' + jQuery(this).attr("id")).on('click', function(event) {
       	                	alert(jQuery(this).attr("id"));
       	                    var myPortletPlaceholderDiv = A.Node.create('<div id="myPortletPlaceholderDiv" class="loading-animation" />');
       	                    myPortletPlaceholderDiv.appendTo("#layout-column_column-2");
       	                    
       	                    var plid = themeDisplay.getPlid();
       	                    var portletId = jQuery(this).attr("id");
       	                    var onComplete = null;
       	                    var beforePortletLoaded = null;
       	     				
       	                    var portletOptions = {
       	                        beforePortletLoaded: beforePortletLoaded,
       	                        onComplete: onComplete,
       	                        plid: plid,
       	                        portletId: portletId,
       	                        placeHolder: '#myPortletPlaceholderDiv'
       	                    };
       	                   
       	                    Liferay.Portlet.add(portletOptions);
       	                    
       	                });
       	    		});
            }
        );
        </script>

<theme:defineobjects />

<c:set var="imagesPath" value="${themeDisplay.pathThemeImages}" />

<c:set var="multiColorPath" value="${themeDisplay.pathColorSchemeImages}" />


<div id="htmlAddWidget">

	<table title="Hello!">
		<tbody>
			<tr>
				<td colspan="2"><h2>Hello We-Ners</h2></td>
			</tr>
			<tr>
				<td><a href="javascript:;" id="myPortlet_WAR_myPortlet" class="portlet">Add Portlet</a></td>
				<td><a href="javascript:;" id="myPortlet2_WAR_myPortlet2" class="portlet">Add Portlet2</a></td>
			</tr>
			<tr>
				<td><a href="javascript:;" id="myPortlet3_WAR_myPortlet3" class="portlet">Add Portlet3</a></td>
				<td><a href="javascript:;" id="myPortlet4_WAR_myPortlet4" class="portlet"> Add Portlet4</a></td>
			</tr>
		</tbody>
	</table>

</div>


[]'s
thumbnail
Jignesh Vachhani, módosítva 11 év-val korábban

RE: Adding portlets using JSP and jQuery

Liferay Master Bejegyzések: 803 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
Please check browser console , Is there any error in browser console ?
Normally this kind of problem occurred when some javascript error comes or some of the tags could be closed properly.
Also if javascript DOM doesn't load properly then also it may happen.
Alexandre Vaz, módosítva 11 év-val korábban

RE: Adding portlets using JSP and jQuery

New Member Bejegyzések: 4 Csatlakozás dátuma: 2012.08.24. Legújabb bejegyzések
No errors in browser console.

What could make javascript DOM not to load properly?
Alexandre Vaz, módosítva 11 év-val korábban

RE: Adding portlets using JSP and jQuery

New Member Bejegyzések: 4 Csatlakozás dátuma: 2012.08.24. Legújabb bejegyzések
Same problem here and here... Anybody?

I've tried this:

I added document.write("<META HTTP-EQUIV='Refresh' CONTENT='2'>");
after line "Liferay.Portlet.add(portletOptions);"

It works that we don't have to refresh a page when calling portlet


But i've got no results.

[]'s
thumbnail
Ritabrata Mukherjee, módosítva 9 év-val korábban

RE: Adding portlets using JSP and jQuery

New Member Bejegyzések: 21 Csatlakozás dátuma: 2014.03.12. Legújabb bejegyzések
Alexandre,
I am also getting the same issue when adding portlets programmatically using JavaScript. I have to refresh the page to display the added portlets. Were you able to find a solution to this ?
thumbnail
Ritabrata Mukherjee, módosítva 9 év-val korábban

RE: Adding portlets using JSP and jQuery

New Member Bejegyzések: 21 Csatlakozás dátuma: 2014.03.12. Legújabb bejegyzések
In case required by anyone, I used the attached code to achieve this on DOM ready. This code is based on portlet.js and layout.js provided by Liferay default. I used Liferay 6.1 EE GA2 for my tests.