Opening a popup inside portlet

Opening a dialog box from portlet is one of the uncommon requirements, but i wanted to try that. Basic idea is opening a dialog box from portlet is normal as opening it from any other web application, but the problem is when you want to open a dialog box from any other web application.

I built this sample portlet which opens www.google.com in the dialog box like this


Inside the doView() method of the portlet i am forwarding control to index.jsp which is like this

<%@page language="java" contentType="text/html; %>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/portal.tld" prefix="portal" %>

<portlet:defineObjects />
<h3>Popup portlet</h3>

<script type="text/javascript">
<!--
function openPopup(popupUrl){
if (window.showModalDialog) {
window.showModalDialog(popupUrl,
"name","dialogWidth:255px;dialogHeight:250px");
} else {
window.open(popupUrl,'name',
'height=500,width=500,toolbar=no,directories=no,
status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
}
}
//-->
</script>

<input type="button" onclick="openPopup('www.google.com')"
label="Open popup" value="Open Popup" />


When user clicks on Open popup button i am calling openPopup() method in JavaScript which takes care of opening popup

No comments: